简体   繁体   English

linux系统环境变量和用户环境变量

[英]linux system environment variables and user environment variables

I have been confused with the question that why user environment variables can't work if system environment variables existing. 我一直对以下问题感到困惑:如果存在系统环境变量,为什么用户环境变量不能工作。

Rencently i installed and configured the python2.7 in linux. 我最近在Linux中安装并配置了python2.7。 There was a python version 2.6.7 in linux Linux中有一个python 2.6.7版本

/usr/local/bin/python

so I had to set environment variable. 所以我必须设置环境变量。 Through internet I obtained the means to set the path 通过互联网,我获得了设置路径的方法

vi ~/.bash_profile(vi ~/.bashrc)
#add export PATH=$PATH:path_python_installed
source /etc/profile

But I have no idea why it doen't work. 但是我不知道为什么它不起作用。 My solution is 我的解决方案是

#add alias python=path_python_installed/python

R installation was the same. R安装是相同的。

If you have a path in $PATH which already contains the 2.6.7 version, it will find that binary first. 如果$ PATH中已经包含2.6.7版本的路径,它将首先找到该二进制文件。

Try echo $PATH and see if any of those paths include the older Python binary. 尝试echo $ PATH,看看这些路径中是否包含旧的Python二进制文件。 You might want to set PATH to; 您可能希望将PATH设置为;

export PATH=path_to_new_python:$PATH 导出PATH = path_to_new_python:$ PATH

You have to add the new search path to the front of PATH: 您必须将新的搜索路径添加到PATH的前面:

 export PATH=/my/new/python/installation/bin:$PATH

When you enter python at the command prompt, the shell tries to find a file name python in any of the folders that are listed in $PATH. 在命令提示符下输入python时,shell尝试在$ PATH中列出的任何文件夹中找到文件名python。 The first match will be used. 将使用第一个匹配项。

Drop the #add in front of the export and the alias commands. #add放在export和alias命令前面。 # is used to start a comment in Bash script. #用于在Bash脚本中启动注释。 Wherever you found these, he must have added the #add as simply a directive. 无论您在哪里找到这些,他都必须添加#add作为简单的指令。

UPDATE: You will also want to do what Bernhard has mentioned in his answer. 更新:您还将想要做Bernhard在他的回答中提到的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM