This post originally featured on the Echo & Co. blog.
On Snow Leopard, you can install drush without using sudo. A dependency for installing drush is downloading a Pear library. The following example should allow you to be able to use the following commands to install drush to /usr/local/drush with a symlink in /usr/local/bin/drush, but it fails on the ‘pear download’ step, even though it’s writing to a user-writeable directory. Read on the figure out how to fix this annoying problem.
1 2 3 4 5 6 7
This assumes 1) /usr/local exists and you can write to it, and 2) you’ve added the following to your ~/.profile (or ~/.bashrc or ~/.bash_profile):
1 2 3
But, OS X has a strange permissions problem when using pear for the first time. Running ‘pear download’ should not require sudo, but if you’ve never used pear before you’ll get this error:
1 2 3 4 5 6 7 8
Strange, right? Administrators in OS X are in the wheel group, but /usr/lib/php is not writable by the group. Before you go changing permissions (which might not be retained after an OS X update), all you have to do is run something as root with pear:
1 2 3 4 5 6 7 8 9
The permissions and ownership of /usr/lib/php are still the same, but there is now the file /usr/lib/php/.lock
You’d think that when pear has completed running the list command it would delete the .lock file, but it doesn’t. But since it’s there, the original pear download command will now run without sudo:
1 2 3 4 5
Of course, running ‘pear install’ or many other commands will require sudo, but it’s silly that commands that do not write any files to /usr/lib/php or its children would require sudo.
Unrelated to the pear permissions issue, but related to my drush install script; this assumes that /usr/local and /usr/local/bin exist. By default, /usr/local/bin is in the $PATH regardless of whether or not the folder exists, but on a vanilla OS X install /usr/local does not exist. I have both Xcode and homebrew installed. I know homebrew will create /usr/local for you, but I’m not sure about Xcode. If you don’t want to have either installed but want drush installed to /usr/local, run this: