0

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?

Pratik Patel
  • 2,209
  • 3
  • 23
  • 30

4 Answers4

4

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.
Pratik Patel
  • 2,209
  • 3
  • 23
  • 30
0

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.

Charles Srstka
  • 16,665
  • 3
  • 34
  • 60
0

For macOS Monterey - Version 12.4, neither ~/.bash_profile nor .profile is working. Creating .zprofile worked for me.

0

First Install "adb" as command

1- print

echo $path 

2- open editor

vim /etc/paths

3- to make “insert” mode Click on “I”

4- copy/past the environment variable example:

/Users/abdallahandroid/Library/Android/sdk/platform-tools
/Users/abdallahandroid/Library/Android/sdk/platform-tools/adb
/Users/abdallahandroid/Library/Android/sdk/emulator

5- Press ""Esc"" then write + write colon”:” it will navigate to last line of editor

6- write “wq” + click enter

7- close terminal and open again, test print

echo $path

Case when save print error "E212" see

bug: vim when save print "/etc/paths" E212:

Abdallah Mahmoud
  • 491
  • 1
  • 5
  • 8