First, a little intro about PATH. It’s a system variable used in terminal (in OS X). It’s the place where the os looks for commands to be executed, it’s very useful since it allows you to just type “less” instead of “/usr/bin/less”; that works for every originally installed commands on the system. However, if you want to be able to type a command like “mysql” for instance, you have to tell the system where to look, you do this by adding the directory to PATH. You can do this every time by doing “export PATH=$PATH:/usr/local/mysql” or by adding this to some initial script executed by the shell.
So, it’s useful to add directories to the PATH variable so it’s easy to execute commands without locating them in their directories every time. There is a very simple way to do this instead of executing some command in the beginning of every session or adding it to some script, just create a file inside /etc/paths.d , for instance if I’d like to append the mysql directory to the PATH I would do this:
- Create the file /etc/paths.d/mysql like this: sudo touch /etc/paths.d/mysql
- Edit the file: sudo vim /etc/paths.d/mysql
- Put the path inside the file: /usr/local/mysql/bin
I posted three steps so everyone knows what they’re doing, but you could do it all by just creating the file and filling it with the paths needed in PATH.
This method works better because it is more ordered at the end and you would have a file for each path you want to add to the PATH variable.
