99

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable. Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.

When i did echo $PATH I got -

/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

I searched on how to remove variables from $PATH and followed these steps :

  1. Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
  2. Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
  3. gave the command export PATH
  4. Closed terminal and reopened it. Gave the command echo $PATH. This time I got /Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

Can anyone tell me what am i doing wrong?

Tushar Koul
  • 2,830
  • 3
  • 31
  • 62

10 Answers10

218
  1. echo $PATH and copy it's value
  2. export PATH=""
  3. export PATH="/path/you/want/to/keep"
Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
user3890550
  • 2,297
  • 2
  • 11
  • 3
40

Check the following files:

/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist

Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • ~/.profile returned "no such file" and all others returned "permission denied" – Tushar Koul Apr 08 '13 at 09:27
  • You need superuser permissions for editing files in `/etc`. You should be able to at least read all of the files, though (provided they do exist). What are the permissions on the files? (`ls -el filename`) – Ansgar Wiechers Apr 08 '13 at 09:46
  • whats the difference between bashrc in the /etc directory and the bashrc in the ~/ directory? – Tushar Koul Apr 09 '13 at 06:05
  • 2
    The one in `/etc` affects all users, the one on your home directory (`~`) only your own user. And the settings in `~/.bashrc` take precedence over the ones in `/etc/bashrc`. – Ansgar Wiechers Apr 09 '13 at 08:59
  • To me changing in `~/.profile` worked. I'm using MAC `OS X El Capitan`. I think by default, it's taking from `~/.profile` – Crocode Oct 23 '16 at 00:22
  • Other options: `~/.zshrc` and `~/.zprofile`. – Noumenon Feb 09 '21 at 18:18
  • @AnsgarWiechers You should also add `/etc/paths` file and `/etc/paths.d` directory to the list. – ObiHill Apr 12 '21 at 10:56
31

On MAC OS X Leopard and higher

cd /etc/paths.d

There may be a text file in the above directory that contains the path you are trying to remove.

vim textfile //check and see what is in it when you are done looking type :q 
//:q just quits, no saves

If its the one you want to remove do this

rm textfile //remove it, delete it

Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.

Timothy L.J. Stewart
  • 1,584
  • 19
  • 15
18

What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.

devnull
  • 118,548
  • 33
  • 236
  • 227
  • 4
    i'm sorry, i didn't quite get what you are saying. Where should I add the ${HOME}\.bashhrc command? – Tushar Koul Apr 08 '13 at 06:52
  • 1
    and I was aware of the commands being valid for the current terminal session. Thats why i thought "export" would work – Tushar Koul Apr 08 '13 at 06:55
  • Add the commands in steps 1 & 3 to the file `${HOME}/.bashrc` (at the end of the file). Open a new terminal and execute `echo $PATH`. – devnull Apr 08 '13 at 06:56
  • Simply `export VARIABLE=VALUE` wouldn't persist `VARIABLE` for all sessions. You need to say that in a startup file, e.g. `${HOME}/.bashrc` or `/etc/profile` (if the changes are intended for all users on the system). – devnull Apr 08 '13 at 06:58
  • I opened the file using `nano ~\.bashrc`..it already had `export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH` there. Also, when i try to edit and save I'm getting Permission denied. – Tushar Koul Apr 08 '13 at 07:11
  • 1
    adding in bash_profile helped me remove it from PATH variable. I opened it using `sudo nano ~/.bash_profile` – Tushar Koul Apr 09 '13 at 07:33
  • for me it's `${HOME}/.zshrc` file – Kirit Vaghela Dec 15 '21 at 06:17
10

If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.

Noumenon
  • 5,099
  • 4
  • 53
  • 73
6

$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.

Here is a good list to run through progressively [copied from @Ansgar's answer with minor updates].

/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/

Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:

/path/to/fancy-app

This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.

ObiHill
  • 11,448
  • 20
  • 86
  • 135
  • This was exactly what I needed to find the culprit. /etc/paths.d/ had the bad entry. Thanks @BannerMan – Brod May 26 '21 at 18:52
4

Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.

Tim Visée
  • 2,988
  • 4
  • 45
  • 55
0

when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)

abasu
  • 2,454
  • 19
  • 22
0

Close the terminal(End the current session). Open it again.

Olu Adeyemo
  • 825
  • 9
  • 17
0

If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.

I found a small script that kept adding some more path in front of the $PATH everytime it was open. For zsh you can check the ~/.zshrc file.

CrmXao
  • 937
  • 2
  • 16
  • 19