112

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
  • 37,153
  • 75
  • 206
  • 328
  • 1
    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

5 Answers5

199

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
  • 4,695
  • 4
  • 23
  • 32
35

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.
  • 1,956
  • 8
  • 28
  • 40
9

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,322
  • 1
  • 16
  • 27
MasterCassim
  • 8,874
  • 3
  • 23
  • 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
7

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
Pmpr.ir
  • 16,260
  • 23
  • 83
  • 97
Jay Sampat
  • 165
  • 1
  • 7
5

use

~/.bash_profile

or

~/.MacOSX/environment.plist

(see Runtime Configuration Guidelines)

Pmpr.ir
  • 16,260
  • 23
  • 83
  • 97
cody
  • 3,193
  • 1
  • 20
  • 23