After installing nodenv as a general user and passing it through the path When I was a little root and had a need
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo su
[root@ip-xxx-xxx-xxx-xxx ec2-user]# su shindev
[shindev@ip-xxx-xxx-xxx-xxx ec2-user]# cd
[shindev@ip-xxx-xxx-xxx-xxx ~]# git clone nodenv〜
[shindev@ip-xxx-xxx-xxx-xxx ~]# vi ~/.bash_profile
#PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/.nodenv/bin
#export PATH
#eval "$(nodenv init -)"
#I added this and passed the path of nodenv
[shindev@ip-xxx-xxx-xxx-xxx ~]# source ~/.bash_profile
[shindev@ip-xxx-xxx-xxx-xxx ~]# nodenv -v
nodenv 1.4.0+3.631d0b6 #Passed
[shindev@ip-xxx-xxx-xxx-xxx ~]# exit
[root@ip-xxx-xxx-xxx-xxx ec2-user]#
#Get a little done
[root@ip-xxx-xxx-xxx-xxx ec2-user]# su shindev
#Switch to general user again
[shindev@ip-xxx-xxx-xxx-xxx ec2-user]#
[shindev@ip-xxx-xxx-xxx-xxx ~]# nodenv -v
bash: nodenv:Command not found#Oh? ??
I should have put a command to pass the bus in bash_profile, but it is not loaded ~ By the way, I'm not sure under what conditions bashrc and bash_profile are read. I will investigate it seriously.
Add echo command to each file though it's not a mess.
bashrc
# .bashrc
echo "~/.bashrc loaded" #Add this
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
bash_profile
# .bash_profile
echo "~/.bash_profile loaded" #Add this
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/.nodenv/bin
export PATH
eval "$(nodenv init -)"
At last, become root and switch with the su command.
[root@ip-XXX-XXX-XXX-XXX ~]# su shindev
~/.bashrc loaded #Only bashrc was read
[shindev@ip-XXX-XXX-XXX-XXX root]$
[root@ip-XXX-XXX-XXX-XXX ~]# su - shindev #Switch with hyphen
Last login: 2020/10/11 (Day) 17:12:21 JSTDay時 pts/0
~/.bash_profile loaded #It was read!
~/.bashrc loaded
[shindev@ip-XXX-XXX-XXX-XXX ~]$
It was that. With or without hyphen in su command, the current path after switching is It was recognized as it was or moved to the home directory of the switching user, It was a story that I had to think about properly.
No hyphen is an impersonal paste In my usual work, I should do it with a basic hyphen.
**end. ** **
Recommended Posts