How to remove entry from $PATH on mac

MacosBashTerminal.Bash ProfilePath Variables

Macos Problem Overview


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?

Macos Solutions


Solution 1 - Macos

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

Solution 2 - Macos

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 3 - Macos

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 4 - Macos

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 5 - Macos

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

Solution 6 - Macos

$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.

Solution 7 - Macos

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.

Solution 8 - Macos

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)

Solution 9 - Macos

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTushar KoulView Question on Stackoverflow
Solution 1 - Macosuser3890550View Answer on Stackoverflow
Solution 2 - MacosAnsgar WiechersView Answer on Stackoverflow
Solution 3 - MacosTimothy L.J. StewartView Answer on Stackoverflow
Solution 4 - MacosdevnullView Answer on Stackoverflow
Solution 5 - MacosNoumenonView Answer on Stackoverflow
Solution 6 - MacosObiHillView Answer on Stackoverflow
Solution 7 - Macosuser1939358View Answer on Stackoverflow
Solution 8 - MacosabasuView Answer on Stackoverflow
Solution 9 - MacosfrancView Answer on Stackoverflow