Check out this Super User explanation of environment variables
We sometimes need to add folders containing programs to the PATH-variable to make them executable from the command line.
Go to Control Panel > System and Security > System
and click on Advanced System Settings.
In the new windows, go to Advanced
then click on Environment Variables
at the bottom.
In the new window that pops up, select Path in the list and the click Edit.
Here you can remove or add different folders to the path. Every folder added here can be accessed from the command line. If there is an executable
file in these folders, you can run it from the command line (normally). Click on New
to add a new folder of your choice.
If I want to add so I can start Sublime from the terminal I can add the folder that Sublime is in on my computer.
C:/Program Files/Sublime Text 3
In this folder I have the program subl.exe
. If this folder is in my path I can write subl
from the command line and Sublime will open in a new window. You can also open specific files with subl file.txt
for example.
You are probably running bash
if you are starting your terminal on macOS. If you want to learn more about using bash
you can read this guide: bash-guide@GitHub. bash
has a configuration-file in your homefolder where you can set the env variables. You can edit this configuration by running this command in the terminal:
nano ~/.bash_profile
You should get a windows that looks something like this. It's and editor in the terminal window. Here you can add your environment variables
You save by pressing Ctrl + O
and exit by pressing Ctrl + X
.
The syntax for doing this is:
export PATH=$PATH:/path/to/folder
For example, this folder should already be in your path but it's just an example:
export PATH=$PATH:/usr/local/bin
When you are done you need to reload bash
so it recognizes the changes
. ~/.bash_profile
You can also created symbolic links to programs so you can start them from the terminal. You basically create a shortcut from their folders to /user/local/bin
which probably already is in your path
. Change the name at the end of the command to whatever you want. In these examples you will start sublime with sublime
and atom with atom
.
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom
sudo ln -s /Applications/Brackets.app/Contents/Resources/brackets.sh /usr/local/bin/Brackets
If you are getting installation errors when installing npm packages globally on macOS just run this command in the terminal and enter your password:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
It will change permissions for the folders that npm packages are installed in. Source