bash 如何从 Mac 上的 $PATH 中删除条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15872666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove entry from $PATH on mac
提问by Tushar Koul
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.
我试图安装 Sencha Touch SDK 工具 2.0.0 但无法正常运行。它在 $PATH 变量中创建了一个条目。后来我删除了sencha sdk工具文件夹,但没有意识到路径变量还在那里。
When i did echo $PATH
I got -
当我这样做时,echo $PATH
我得到了 -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
/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 :
我搜索了如何从 $PATH 中删除变量并按照以下步骤操作:
- Gave the command
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
- Did
echo $PATH
which showed/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
- gave the command
export PATH
- 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
- 下了命令
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
- 做了
echo $PATH
哪些显示/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
- 下达了命令
export PATH
- 关闭终端并重新打开它。下达了命令
echo $PATH
。这次我得到/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?
谁能告诉我我做错了什么?
采纳答案by devnull
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
.
您所做的对当前会话有效(仅限于您正在使用的终端)。您需要坚持这些更改。考虑将上述步骤 1-3 中的命令添加到您的${HOME}/.bashrc
.
回答by user3890550
echo $PATH
and copy it's valueexport PATH=""
export PATH="/path/you/want/to/keep"
echo $PATH
并复制它的值export PATH=""
export PATH="/path/you/want/to/keep"
回答by Ansgar Wiechers
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.
其中一些文件可能不存在,但它们最有可能包含$PATH
定义。
回答by Timothy L.J. Stewart
On MAC OS X Leopard and higher
在 MAC OS X Leopard 及更高版本上
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 linkto a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
回答by devnull
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.
sudo pico /etc/paths
在终端窗口内使用并将条目更改为要删除的条目,然后打开一个新的终端会话。
回答by abasu
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)
当您登录或启动 bash shell 时,会根据 .bashrc 或 .bash_profile 加载/配置环境变量。无论您在做什么导出,它都只对当前会话有效。因此,export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH
每次打开 shell 时都会执行此命令,您可以覆盖它,但同样仅适用于当前会话。编辑 .bashrc 文件以满足您的需要。如果它说权限被拒绝,也许该文件被写保护,一个指向其他文件的链接(许多组织保留一个主 .bashrc 文件并为每个用户提供一个指向其主目录的链接,您可以复制该文件而不是链接并开始向其添加内容)
回答by franc
Close the terminal(End the current session). Open it again.
关闭终端(结束当前会话)。再打开。