Question: On osx/linux I want to be able to run a command/script on the terminal from anywhere which links to a program.

ie I want to be able to run:

alloy

that runs:

`/usr/local/share/npm/lib/node_modules/alloy/bin/alloy`

I'm guessing adding to .bashrc is the best way? I've tried running:

`export PATH="$PATH:/usr/local/share/npm/lib/node_modules/alloy/bin"`

and also:

```
export PATH="$PATH:/usr/local/share/npm/lib/node_modules/alloy/bin/alloy"

```

Then I started a new terminal window but the alloy command doesnt work. Am I missing something?

Answer: 
The best place to add to PATH is not the ~/.bashrc file, but the ~/.bash\_profile if it exists. If .bash\_profile does not exist, the best place is ~/.profile. The ~ part is automatically expanded to be your home directory (`/home/you`).

When you login and execute bash as the "login shell", it reads .bash\_profile. If it is not found, it reads .profile. The **.bashrc is NOT read** in this case (unless it is explicitly called from inside .bash\_profile). I rarely put anything in .bashrc; one thing that supposedly should go there are aliases if you'd like to use some.

To stay compatible with some old logon shells (like ksh88), which also read .profile, you could alternatively use a separate export line there:

```
PATH="$PATH:/usr/local/share/npm/lib/node_modules/alloy/bin"
export PATH

```

Your syntax is correct for .bash\_profile:

```
export PATH="$PATH:/usr/local/share/npm/lib/node_modules/alloy/bin"

```

You can test it immediately, just enter one of above into your actual bash command line, and then try to see if it is recognized:

```
echo "$PATH"
which alloy
alloy

```

Now, as a test of your .bash\_profile or .profile, login on a new session (not open just another terminal window, but really use your login and password).

To enable the same setting for all system users, change /etc/profile or /etc/profile.d, depending on your Linux flavor. This is a system-wide profile, read on each login before the ~/.bash\_profile or ~/.profile.
One simply solution to this that doesn't require manipulating the path is to simply create a symlink to the application in the `/usr/local/bin` or `/usr/local/sbin` folders, since those folders are already in your path. I often use this for programs that install to `/opt`, `/usr/local` or other places which are not in the path by default.

```
ln -s /usr/local/share/npm/lib/node_modules/alloy/bin/alloy /usr/local/bin/alloy

```

Of course this might not always work if the program requires that it be run from a certain working directory, if a program had such a requirement, it would also be not work if you changed the PATH. I occasionally see this for badly design scripts that assume they are being called from a certain path.