如何更改$ PATH的顺序?(How do I change the order of $PATH?)

编程入门 行业动态 更新时间:2024-10-07 14:33:48
如何更改$ PATH的顺序?(How do I change the order of $PATH?)

echo $PATH给我

/Library/Frameworks/Python.framework/Versions/3.4/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

但是当我想将usr / local / bin的顺序更改到/Library/Frameworks/Python.framework/Versions/3.4/bin的前面时,我键入

sudo emacs /etc/paths

只要

/usr/local/bin: /usr/bin: /bin: /usr/sbin: /sbin: 我如何将/usr/local/bin的顺序更改为第一个? 我可以删除不再有用的那些,例如/Library/Frameworks/Python.framework/Versions/3.4/bin ,以及如何? 因为我删除Python.framework? 更改订单后如何保存更改?

echo $PATH gives me

/Library/Frameworks/Python.framework/Versions/3.4/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

but when I want to change the order of /usr/local/bin to the front of /Library/Frameworks/Python.framework/Versions/3.4/bin, I type

sudo emacs /etc/paths

I only get

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

How can I insert /usr/local/bin in front of my PATH?

最满意答案

您可以在主目录中的.bash_profile中设置PATH,例如:

emacs ~/.bash_profile

然后通过在其中放置适当的export语句将其设置为你想要的:

export PATH=/usr/local/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

更好的解决方案是将append / prepend追加到现有路径中,如下所示:

export PATH=/usr/local/bin:$PATH

注意:这不是您可以设置PATH的唯一位置,但它是常见的。

You can set your PATH in the file .bash_profile, which is in your home directory.

More specifically, you can simply add the following line to the end of that file

export PATH=/usr/local/bin:$PATH

This results in /usr/local/bin being prepended to the existing PATH. In other words, the folder /usr/local/bin is inserted in front of your PATH, and so it would have the highest priority. You can also append a folder to your path by doing

export PATH=$PATH:/usr/local/bin

In general, you can set the order of the folders or files that you export in a similar way as the following:

export PATH=/usr/local/bin:/Applications/Sublime Text 2.app/Contents/SharedSupport/bin:/Users/pathreskoo/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin

Note: this is not the only place you can set the PATH, but it is a common one.

更多推荐

本文发布于:2023-08-04 22:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   如何更改   order   PATH   change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!