134

How to edit PATH variable on mac (Lion). I cannot find any file where I can add paths. can someone guide me about it?

Whats the file name? .profile or .bash_profile???

and where I can find it? I have tried

echo 'export PATH=/android-sdk/tools:$PATH' >> ~/.profile
coure2011
  • 40,286
  • 83
  • 216
  • 349
  • 2
    I have the same exact question! Will someone with the proper authority please move this to the Macintosh/Apple section so it can be opened? – SMBiggs Jun 30 '18 at 16:23
  • I find this question very useful, but maybe you should ask it here: https://apple.stackexchange.com. – Timbergus Mar 09 '21 at 08:18
  • 1
    Add this line to your ~/.zshrc file. export PATH=$PATH:. You can do this multiple times as you are appending the new path variable to the old one. – Anjan Talatam Sep 05 '22 at 13:33

5 Answers5

233

Open and edit /etc/paths using any text editor.

$ sudo vi /etc/paths

(editing text files with vi)

Note: each entry is separated by a new line

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

Save and close the file. Then restart your terminal.

Ryan Allen
  • 5,414
  • 4
  • 26
  • 33
38

Based on my own experiences and internet search, I find these places work:

/etc/paths.d

~/.bash_profile

Note that you should open a new terminal window to see the changes.

You may also refer to this this question

Community
  • 1
  • 1
can.
  • 2,098
  • 8
  • 29
  • 42
11

You could try this:

  1. Open the Terminal application. It can be found in the Utilities directory inside the Applications directory.
  2. Type the following: echo 'export PATH=YOURPATHHERE:$PATH' >> ~/.profile, replacing "YOURPATHHERE" with the name of the directory you want to add. Make certain that you use ">>" instead of one ">".
  3. Hit Enter.
  4. Close the Terminal and reopen. Your new Terminal session should now use the new PATH.

Quoted from ketio.me tutorial (archived copy).

zcoop98
  • 2,590
  • 1
  • 18
  • 31
Tobias
  • 9,170
  • 3
  • 24
  • 30
  • 1
    Yes I have tried that command but it seems nothing happens after pressing enter, I restarted the terminal but still path is not added. – coure2011 Oct 09 '11 at 11:05
10

environment.plst file loads first on MAC so put the path on it.

For 1st time use, use the following command

export PATH=$PATH: /path/to/set
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Jay Sampat
  • 195
  • 1
  • 8
5

use

~/.bash_profile

or

~/.MacOSX/environment.plist

(see Runtime Configuration Guidelines)

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
cody
  • 3,233
  • 1
  • 22
  • 25