Issue
Today, In Centos7, I uninstall nodejs
and npm
and then install by Linux Binaries (x64).
After unzip it ,then move it to /usr/local/nodejs
. To make it global, I config soft link as follows:
#ln -s /usr/local/nodejs/bin/npm /usr/local/bin/
#ln -s /usr/local/nodejs/bin/node /usr/local/bin/
What make me confused is that:
#nodejs -v
OK. However, but, the followin command:
#npm -v
Brings an error that the command cannot found.
Trying some approaches:
After
#ln -s /usr/local/nodejs/bin/npm /usr/bin/
#npm -v
This command runs OK. What's make that different?
Any suggestion is appreciated.
Solution
If you're using bash, you have a file in your home called .bash_profile
. This command runs a set of commands to configure your bash environment.
Also, all the .sh
files inside /etc/profile.d
are executed on every session that you execute.
So, inside those scripts, we have an environment variable called PATH
, that are set on bash start.
If you try to do echo $PATH
, you'll see a set of directories separated by colon :
.
Every time that you try to run a command, the bash will check inside all directories setted inside this $PATH
variable.
If your call are not found, we can get two hypotesis:
Your file or link is on a path that are not contained in
$PATH
dir.Your file are not executable (need to do
chmod
).
So, check your $PATH
to see if your command is linked on the right place, if you have a valid file and, lastly, if the execution permissions are valid.
Answered By - William Prigol Lopes Answer Checked By - Clifford M. (WPSolving Volunteer)