How to remove entry from $PATH on mac

136,836

Solution 1

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.

Solution 2

  1. echo $PATH and copy it's value
  2. export PATH=""
  3. export PATH="/path/you/want/to/keep"

Solution 3

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.

Solution 4

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.

Solution 5

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

Share:
136,836

Related videos on Youtube

Tushar Koul
Author by

Tushar Koul

.

Updated on April 13, 2021

Comments

  • Tushar Koul
    Tushar Koul about 3 years

    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
    Tushar Koul about 11 years
    i'm sorry, i didn't quite get what you are saying. Where should I add the ${HOME}\.bashhrc command?
  • Tushar Koul
    Tushar Koul about 11 years
    and I was aware of the commands being valid for the current terminal session. Thats why i thought "export" would work
  • devnull
    devnull about 11 years
    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
    devnull about 11 years
    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).
  • Tushar Koul
    Tushar Koul about 11 years
    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
    Tushar Koul about 11 years
    ~/.profile returned "no such file" and all others returned "permission denied"
  • Ansgar Wiechers
    Ansgar Wiechers about 11 years
    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)
  • Tushar Koul
    Tushar Koul about 11 years
    whats the difference between bashrc in the /etc directory and the bashrc in the ~/ directory?
  • Tushar Koul
    Tushar Koul about 11 years
    adding in bash_profile helped me remove it from PATH variable. I opened it using sudo nano ~/.bash_profile
  • Ansgar Wiechers
    Ansgar Wiechers about 11 years
    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.
  • Mike Furlender
    Mike Furlender over 8 years
    In the future I advise you to read the body of the question before answering.
  • schalkneethling
    schalkneethling almost 8 years
    Also note that after running export PATH="" you might see errors such as: -bash: tail: No such file or directory -bash: sed: No such file or directory That is expected.
  • Crocode
    Crocode over 7 years
    To me changing in ~/.profile worked. I'm using MAC OS X El Capitan. I think by default, it's taking from ~/.profile
  • zapstar
    zapstar over 5 years
    Also remember to look inside /etc/paths.d/
  • Noumenon
    Noumenon over 3 years
    Other options: ~/.zshrc and ~/.zprofile.
  • ObiHill
    ObiHill about 3 years
    @AnsgarWiechers You should also add /etc/paths file and /etc/paths.d directory to the list.
  • Brod
    Brod about 3 years
    This was exactly what I needed to find the culprit. /etc/paths.d/ had the bad entry. Thanks @BannerMan
  • analyst_47
    analyst_47 almost 3 years
    Quite direct!! Thank you
  • Kirit  Vaghela
    Kirit Vaghela over 2 years
    for me it's ${HOME}/.zshrc file
  • Pawan
    Pawan over 2 years
    export PATH="" is throwing error as zsh: bad assignment