setting path in terminal

大城市里の小女人 提交于 2019-12-13 14:34:26

问题


I am installing Homebrew on my Mac in order to install Macvim. After installing Homebrew, I am prompted to run brew doctor, which in turn generates a number of warnings. I have resolved several of these but am stuck on two:

Warning: Enthought Python was found in your PATH. This can cause build problems, as this software installs its own copies of iconv and libxml2 into directories that are picked up by other build systems.

I'm not sure if I should simply ignore this or look for a way to uninstall Enthought Python.

Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. The following tools exist at both paths:

git
git-cvsserver
git-receive-pack
git-shell
git-upload-archive
git-upload-pack

Consider setting your PATH so that /usr/local/bin occurs before /usr/bin. Here is a one-liner: echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile

I have run

echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile

several times but continue to get the same warning. Here is my PATH

nngrey$ echo $PATH
/Users/nngrey/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/bin:/Users/nngrey/.rvm/gems/ruby-2.0.0-p247@global/bin:/Users/nngrey/.rvm/rubies/ruby-2.0.0-p247/bin:/Users/nngrey/.rvm/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Users/nngrey/bin

Okay, I found the answer to my second question here: How to modify PATH for Homebrew?

I just needed to restart the terminal. Still not sure what to do about Python, though.

Any suggestions would be appreciated. Thanks


回答1:


To solve both issues: Edit your ~/.bash_profile file

The /usr/bin occurs before /usr/local/bin warning:

This warning is telling you that the $PATH environment variable is listing /usr/bin as higher priority than /usr/local/bin, which I presume is the default location that home brew installs packages to.

If you ignore this, then this means that if you install or upgrade a program using 'home brew' after already having that program previously installed (without using 'home brew') to different location, the shell might invoke commands using the older copy and not the newer 'home brew'-installed version.

The $PATH variable is perhaps the most important of Unix Shell environment variables (you can type env to list the environment variables in the shell) in that it defines the order of directories in which the computer will search when looking for programs to execute. The highest priority path names are specified first.

You can view the contents of your ~/.bash_profile by typing in Terminal.app:

$ cat ~/.bash_profile

Remember: don't type the $, it just indicates the Terminal prompt.

It should print out something like this:

# Setting PATH for EPD_free-7.3-2
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH

Note that Enthought's comment indicates that they preserved the original ~/.bash_profile in a copy called .bash_profile.pysave in the same directory ($HOME). If you want you can view that file, check it out with cat or a text editor. If you decide to revert back to it, you can do so by removing the ~/.bash_profile file and by renaming .bash_profile.pysave to .bash_profile. (This wasn't an option for me, as I must have in the past installed Enthought's distribution a second time (possibly on top of itself), so my .bash_profile.pysave still contained Enthought's configurations, and my ~/.bash_profile. listed two copies of the Enthought configurations.)

This is the Enthought distribution setting the $PATH env variable to ${PATH}. To show what the ${PATH} variable holds, lets enter echo $PATH into the shell. It should show that Enthought's own directories have first priority (because they come first):

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin

If you look closely at the above example, you can see that /usr/local/bin occurs twice in the list (!), once in third position and once in the second to last position. /usr/bin occurs between them, but the parser for brew doctor is detecting a problem (this could be a brew doctor bug that is only checking for a trailing /usr/local/bin, but there is almost certainly an Enthought bug because they left my $PATH definition with two /usr/local/bin's in there. If you don't see /usr/local/bin/ twice, then it could be because I may have had installed Enthought twice on my end.).

So, even though there may not really be a problem here, brew doctor still thinks so and we also still need to get rid of Enthought's directories placed with highest priority, because those entries could interfere if we wanted to acquire a different Python distribution in the future using 'home brew'.

The shell will look to these locations in the $PATH variable from left to right order for executing commands, etc. Remember, the paths are separated by colons (:) and are listed in descending priority from left to right, with highest priority first.

Method 1 - ("Fast and Easy" version):

A) Redefine the $PATH variable, paste this command in Terminal:

$ echo 'export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"' >> ~/.bash_profile

(This will append (the >> operator) the echoed string to the end of the ~/.bash_profile file. If you use this command, you will still need to edit your ~/.bash_profile to remove the Enthought stuff later)

Click here and scroll down to step 3 for more info on this particular command.

Or you can cd into the $HOME directory and add the string in the above command to the your .bash_profile manually, as I show below for removing Enthought's configurations.

B) To disable the Enthought Python distribution, edit your ~/.bash_profile file:

Change to your home directory:

$ cd $HOME

To edit the file in, for instance, TextEdit:

$ open -a "TextEdit" .bash_profile

Find these two lines:

PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH

And comment them out by placing an # in front of each line. Then save the file.

(If you plan on not using the Enthought distribution again, you can delete these lines and the other comments instead of commenting them out)

Method 2 - Edit the file (and solve both problems) using a text editor

(Below explanation assumes unfamiliarity with the vim editor)

$ vim ~/.bash_profile

If you do not have write privileges you may be prevented from changing the ~/.bash_profile file. If so, exit vim (ESC, then type :q) and change to super user by prepending the above vim command with sudo and a space. You can exit sudo ('super user do') later by typing exit once back in the shell.

When vim first opens up, you are presented with the command mode, where typing will not change the file contents at all, but add commands to the prompt at the bottom of the window (such as :q to quit, or :w to write (save) changes).

In vim, you can move around with the arrow keys (or the H, J, K, L keys). Once you've located the line to edit, press the I key to enter -INSERT- mode and start inserting characters before the cursor (Pressing the A key in command mode will also exit command mode but will start inserting text after the cursor).

If you think you might want to use the Enthought distribution in the future, you can comment out all the lines by placing a # at the beginning of each line, like so:

# Setting PATH for EPD_free-7.3-2
# The original version is saved in .bash_profile.pysave
# PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
# export PATH
# export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

If you have no plans to use the Enthought distribution or you have already uninstalled it, just delete all of the above lines from the ~/.bash_profile file.

To declare a new definition for the $PATH environment variable, add this line below:

export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

Once you are done editing the file, press ESC to leave -INSERT- mode and return to command mode. then type :wq to write the changes and quit the vim editor. You will then be returned to the shell.

To finish, source the newly saved ~/.bash_profile by entering:

$ source .bash_profile

If you only commented out the Enthought lines, you'll be able to return to your .bash_profile and enable the Enthought distribution again by uncommenting those two lines.

Now run brew doctor and you should be good to go. If it doesn't run without warnings, kill Terminal and reopen it and try again.

Running echo $PATH should now show:

/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin



回答2:


Unless you need it for something, I'd remove Enthought's version of Python.



来源:https://stackoverflow.com/questions/19102869/setting-path-in-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!