Search code examples
macosbashunixpathenvironment-variables

Setting PATH environment variable in OSX permanently


I have read several answers on how to set environment variables on OSX permanently.

First, I tried this, How to permanently set $PATH on Linux/Unix but I had an error message saying no such file and directory, so I thought I could try ~/.bash_profile instead of ~/.profile but it did not work.

Second, I found this solution How to set the $PATH as used by applications in os x , which advises to make changes in

~/.MacOSX/environment.plist

but again I had no such file and directory error.

I need a way to set these variables such that it won't require setting them again and again each time I open a new terminal session.


Solution

  • You have to add it to /etc/paths.

    Reference (which works for me) : Here


    These are the steps from the referenced article:

    • Open up Terminal.
    • Run the following command: sudo nano /etc/paths
    • Enter your password, when prompted.
    • Go to the bottom of the file, and enter the path you wish to add.
    • Hit control-x to quit.
    • Enter “Y” to save the modified buffer.

    That’s it! To test it, in new terminal window, type: echo $PATH