0

For example, I can run ln, nano, and programs I installed over apt like sl or worms without having to give the full path. However, when I build a program/package/software manually/using make/using something else, I have to invoke it using the full path, in my case ~/ghc/bin/ghc. How do you tell bash, or for that matter, sh, which names exist?

I know how to do this on Windows, but as far as I know, there's no equivalent of %PATH% in Linux/Unix/Ubuntu (in my case).

schuelermine
  • 1,215

1 Answers1

2

There is - the variable is called $PATH.

You may make a program globally accessible by copying it to any path that's listed under $PATH, such as /usr/bin or /usr/local/bin or /bin.

The recommended place to add your own custom binaries is /usr/local/bin though.

You may also add new directories to the $PATH by overwriting the variable in your shell start script (in ~/.bashrc, or ~/.bash_profile):

export PATH="$PATH:/usr/local/myfolder/bin"

You can find out more about the recommended meanings for UNIX filesystem paths here.

boxmein
  • 136
  • To be strict: the variable is called PATH both in Windows and in Unix/Linux. You refer to a variable named foo with %foo% and $foo respectively, hence %PATH% and $PATH; but it's the syntax to retrieve the value that is different, not the name itself. Commands that take name (not value) need no %/$, e.g. set PATH=…. – Kamil Maciorowski May 11 '19 at 19:03
  • Thanks! Why do you use ":" after "$PATH"? – schuelermine May 11 '19 at 19:14
  • 1
    @schuelermine : is the separator between multiple paths in the variable, just like ; in Windows. – boxmein May 11 '19 at 22:27