0
votes

I have recently upgraded my OS to Max OS Sierra and I am trying to save one specific path in the environment variable(PATH variable). I opened Terminal and executed below steps:

  1. echo $PATH

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

  2. export PATH=~/Desktop/:$PATH

  3. echo $PATH

    /Users/pratik/Desktop/:/usr/bin:/bin:/usr/sbin:/sbin:/usr /local/bin

I have closed the Terminal and opened new Terminal and executed below command:

  1. echo $PATH

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

So the path which I have added previously is not getting saved. What am I missing here?

2

2 Answers

3
votes

The ~/.bash_profile is executed each time you open a terminal session(Terminal application) automatically.

So you need to set(export) your environment variables in ~/.bash_profile

  1. First, check if .bash_profile exists in logged in user home(/Users/username) directory.
  2. If not exists then you can create ~/.bash_profile. The easiest way to create it by the touch utility: touch .bash_profile'. You can edit it using any text editor.
  3. Now edit the .bash_profile : vi ~/.bash_profile
  4. Add export PATH=/Users/username/Desktop:$PATH and save
  5. Close the existing Terminal and open a new one.
  6. Type echo $PATH and view the output. Newly added path(/Users/username/Desktop) must be stored in the PATH variable.
0
votes

When you export an environment variable, that applies only to the current session. If you want to permanently add something to your PATH, you should do it in your .profile script, which should go in your home directory.