简体   繁体   中英

python2.7 on centos for non root user

I installed Python2.7.6 on Centos 6.5 using make altinstall. If I do python2.7 -V using root, I get the correct answer.

When I use another user that has sudoers permissions I also see everything as normal.

When I switch to another user that does not have sudoers then I get bash: python2.7: command not found . When I switch back to root or to my other user (after using the non sudoer user), then suddenly I cannot find Python2.7 there either.

How do I get the python to work?

Updated from comments:

Please add path python2.7 to path variable $PATH , in the user's ~/.bashrc or ~/.profile or

for all users add it to /etc/profile

You can do so by finding line like export PATH=$PATH:/path/to/binary1:/path/to/binary2 just add absolute path to python2.7 after placing a : at the end of this line. and source the file on the terminal you are using python2.7 .

For subsequent logins it will work, but If you have added in /etc/profile file then you shall have to either source it every time or restart the machine once after making changes to file.

The answer to other part of the question depends on how you are moving back to root .

move back to root via

sudo su -

or if you do not need sudo then

su -

Difference between su and su -

This is a simple PATH issue.

Modify /etc/profile and add something like:

export PATH="/path/to/python:$PATH"

Normally on many CentOS systems I maintain I install a custom Python to /usr/local/` so my PATH`` modification becomes:

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

Note: This should work in all cases as long as you get the PATH right regardless of which user you are logged in with or the use of sudo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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