Pwdr
Pwdr

Reputation: 3781

How to delete a certain path from $PATH on mac

I need to get rid of /Library/Frameworks/Python.framework/Versions/2.7/bin in my $PATH variable on Mac OS X Lion. I opened several files, which add something to the path but do not find the location which adds the python path. Here is the output of several files and the path variable:

echo $PATH returns

/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Users/friedrich/.rvm/gems/ruby-1.9.3-p362/bin:/Users/friedrich/.rvm/gems/ruby-1.9.3-p362@global/bin:/Users/friedrich/.rvm/rubies/ruby-1.9.3-p362/bin:/Users/friedrich/.rvm/bin:/Users/friedrich/.rbenv/shims:/Users/friedrich/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin

File /etc/paths/

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

File ~/.profile

export PATH=$PATH:/usr/local/git/bin:/usr/local/Cellar/todo-txt/2.9/bin

File ~/.bash_profile

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# todo.txt script path
source /usr/local/Cellar/todo-txt/2.9/etc/bash_completion.d/todo_completion complete -F _todo t

# MacPorts Installer addition on 2013-03-01_at_21:26:56: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

The last file which adds something to the path seems to be .bash_profile adding export PATH=/opt/local/bin:/opt/local/sbin:$PATH, so I need the file adding something one step before that.

Upvotes: 1

Views: 13398

Answers (3)

chepner
chepner

Reputation: 531798

You can trim a fixed part of the path using parameter expansion. Add this to the end of .bash_profile (or at least, late enough that it is processed after the offending path is added):

PATH=${PATH/\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin:}

(All the backslashes are unfortunate, but you at least you only have to type it once.)

Upvotes: 1

dangenet
dangenet

Reputation: 265

There are yet more ways to add things to your PATH on OS X.

In addition to the /etc/paths file, there is a directory /etc/paths.d. In that directory are text files of the same format as /etc/paths. The lines of each file in /etc/paths.d are added to your PATH after the lines in /etc/paths, and before the stuff in .bash_profile (though that depends on exactly what is in .bash_profile).

If your unwanted Python framework path isn't in the above, there are two other places I can think to try. There are also /private/etc/paths and /private/etc/paths.d, and possibly a .bashrc file in your home directory.

I hope that does it for you. If it doesn't, then the workaround I would use would be to make the last command in .bash_profile to append /usr/bin to the front of your PATH. That way the Apple version of Python (which is linked to in /usr/bin) will be found before your framework version of Python.

Upvotes: 2

niculare
niculare

Reputation: 3687

Taking into account the order in which the paths are added to the $PATH variable(so you want to remove the third element), you can add a command like this at the end of your .bash_profile:

 export PATH=`echo $PATH | cut -d":" -f1,2,4-`

Upvotes: 1

Related Questions