2

I have installed a program that did not automatically put its binaries into usr/local/bin for me. This means that "command not found" errors happen very often whenever I run scripts in that program. I can fix this by copy-pasting the binaries into the usr/local/bin directory, but I don't want to do this every single time, for every single binary. What would be a more efficient way to make the scripts work?

Thank you very much in advance!

merah
  • 61
  • 2
  • 10

2 Answers2

0

Add the directory containing the binary to your $PATH environment variable by editing ~/.bash_profile:

export PATH=$PATH:/your/new/path

You can also edit /etc/paths or add a file to /etc/paths.d, but you need to have admin privilege to do that.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0

Executables are simply resolved via the $PATH variable. It's set to something like

PATH="/bin:/usr/local/bin:..."

(Try $ echo $PATH.)

When you enter a command:

$ foo

each path will be tried in turn and the first matching executable will be executed.

/bin/foo 
/usr/local/bin/foo

To execute something outside the default path, simply enter the whole path to the executable:

$ /home/me/bin/foo
$ cd /home/me/bin
$ ./foo

If you find that you need to do that often and want the shortcut, alter your path:

export PATH="$PATH:/home/me/bin"

(Put this in your shell startup script like ~/.profile to automate that.)

Alternatively, symlink the executable to somewhere in your path:

$ ln -s /home/me/bin/foo /usr/local/bin/foo
deceze
  • 510,633
  • 85
  • 743
  • 889
  • OSX doesn't have a `~/.profile` (it's `~/.bash_profile`) and your symlink arguments are back-to-front. – trojanfoe Jul 28 '14 at 09:58
  • OS X *does* have `~/.profile`, I'm using it. And `ln` is defined as `ln [-Ffhinsv] source_file [target_file]`. – deceze Jul 28 '14 at 09:59
  • Of course you can use `~/.profile` but using `~/.bash_profile` would appear to be the more normal option. As for the `ln` command line, I don't think you've thought that through properly. Hang on; unless the new binary is in `/home/me/bin`? – trojanfoe Jul 28 '14 at 10:03
  • OK, I see. I misunderstood. I would have expected `$HOME/bin` to be in the path anyway. – trojanfoe Jul 28 '14 at 10:05
  • Yes, the `ln` example builds on the previous example with `~/bin`. – deceze Jul 28 '14 at 10:06
  • Also: http://stackoverflow.com/questions/6751252/difference-between-profile-and-bash-profile-on-snow-leopard - both are valid options. – deceze Jul 28 '14 at 10:07
  • I'm voting to close the question anyway; this is basic user-stuff. – trojanfoe Jul 28 '14 at 10:09
  • Can't really disagree with that unfortunately. ;) – deceze Jul 28 '14 at 10:11