3

I have snow leopard which apparently has php with pear pre-installed. I enabled php but could not find any signs of PEAR. So I have installed it and now phpinfo() shows its installation

include_path .:/usr/lib/php/share/pear

Still when I type in any pear command

$ sudo pear

I get an error: sudo: pear: command not found

What am I missing?

keeg
  • 3,990
  • 8
  • 49
  • 97

4 Answers4

7

Many ways to skin this cat, but I would type this if you have locate installed (which you probably do):

$ locate bin/pear

That should list one or more things, one of which will look like the path to pear. Let's say it says something like /usr/local/bin/pear. Then your next command is:

$ sudo /usr/local/bin/pear

Two caveats come to mind:

  1. It's possible that locate will list multiple executable pear files. If that's the case, it may be important to pick the right one based on which PHP you're using.
  2. You may want to add the directory where pear is located to your PATH environment variable.
Trott
  • 66,479
  • 23
  • 173
  • 212
  • locate is not installed... I know the path which is /usr/lib/php/share/pear but the weird thing is that even if i go to that directory i still can't run pear – keeg Jun 03 '11 at 05:04
  • That's not the directory where the pear command-line binary is installed. What happens when you type `locate bin/pear` in a terminal prompt? Locate is installed by default on every Mac OS X installation I've ever seen, so I'm suprised to see you say it is not installed. If it truly is not installed, try `whereis pear`. – Trott Jun 03 '11 at 05:13
  • If all else fails, you can try `sudo /usr/local/bin/pear` and `sudo /usr/local/php5/bin/pear`. I've seen pear end up in both locations on Mac OS X. If you **really** have no idea where it is but are certain it's there somewhere, and you can afford to be very patient you can try something thorough but inefficient like: `sudo find / -name pear` but that could take a long time to run. I would be prepared to give it hours at a minimum. That would be for truly desperate times only, I suspect. (And it might be a bad idea to run on a production server.) – Trott Jun 03 '11 at 05:22
  • so locate says: The locate database (/var/db/locate.database) does not exist. – keeg Jun 03 '11 at 05:24
  • whearis pear returns nothing, just goes to the next line – keeg Jun 03 '11 at 05:24
  • Oh, OK, so locate is installed, but the database has never been set up. If you can afford to be patient, you can run `sudo /usr/libexec/locate.updatedb` to set it up. (I'm assuming you're on a dev machine here and not a production server.) You'll want to set up a cronjob to keep locate up to date. (Google it or look on ServerFault.com.) In the mean time, did you find it in `/usr/local/bin/pear` or `/usr/local/php5/bin/pear` by any chance? – Trott Jun 03 '11 at 05:27
  • generating the database for locate . Says it could take some time, no idea how long that is, still not working – keeg Jun 03 '11 at 05:32
  • How about this?: `find /usr -name pear | grep bin/pear` – Trott Jun 03 '11 at 05:33
  • pear located: /usr/lib/php/share/pear/PEAR – keeg Jun 03 '11 at 05:34
  • You sure that `/usr/lib/php/share/pear/PEAR` isn't a directory rather than the command-line for pear that you're looking for? Because if that's the executable, you have one crazy pear setup. :-) – Trott Jun 03 '11 at 05:37
  • i lied, i searched for just pear, when i search for bin/pear i get: /usr/lib/php/bin/pear && /usr/lib/php/bin/peardev – keeg Jun 03 '11 at 05:38
  • 1
    Cool! So now you can either always type `sudo /usr/lib/php/bin/pear` when you want to use it, or you can follow @hayashi-kei's instructions but use this for the line to add: `export PATH=/usr/lib/php/bin:$PATH` – Trott Jun 03 '11 at 05:50
  • sudo pear still doesn't work but at least something works! Thanks Trott! – keeg Jun 03 '11 at 05:59
  • haza! got it working, your path was correct, @hayashi-kei had an example path and I blindly copied it. DUH. But export PATH=/usr/lib/php/bin:$PATH works perfect. Thanks again! – keeg Jun 03 '11 at 06:06
7

You need to update your system $PATH variable in order for the pear command to work. Edit the bash profile file using the following(if you have textmate):

mate ~/.bash_profile

and add in this line:

export PATH=/usr/local/pear/bin:$PATH

reload your terminal after that and it should work now

Edited: Thanks for highlighting my mistake trott. I have changed the path to locate where the bin should roughly be(depending on where one chooses to install it)

David Lin
  • 631
  • 8
  • 10
  • So I do have textmate but of course I get mate command not found. I added the path to .bash_profile but it was a new file, so maybe I did it in the wrong spot cause it's still not working – keeg Jun 03 '11 at 05:00
  • 1
    I'm fairly certain /usr/lib/php/share/pear is not the path of the actually command-line binary, so I do not think this will work. include_path is the location of PHP files included by things like include() and require(). It would be very surprising and thoroughly facepalm-worthy to find out that the command-line binary is stashed in the same directory. – Trott Jun 03 '11 at 05:17
2

If you have installed pear directly on PHP (MAMP, for example) you should copy pear to /usr/local/bin:

cp /php5.3.2/pear /usr/local/bin/pear

then export var PATH, and test with "pear" in the shell.

aurny2420289
  • 481
  • 5
  • 16
0

I had a similar issue and required updating secure_path in sudoers as it overrides user's $PATH.

Check for secure_path on sudo

[root@host ~]# sudo -V | grep 'Value to override'
Value to override user's $PATH with: /sbin:/bin:/usr/sbin:/usr/bin

If $PATH is being overriden us visudo and edit /etc/sudoers

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
codemonkee
  • 2,881
  • 1
  • 25
  • 32