while Installing Node JS 4.8 on Centos 7 installs

2019-07-18 18:30发布

Currently I tried installing Node Js specific version 4.8 on my Centos-7 64 bit machine. Using below commands

#  curl -sL https://rpm.nodesource.com/setup_4.x | bash -
#  yum install -y nodejs

But when I check the Node version it show 6.11.1

I want to install Node Js for Meteor 1.5.0 and specifically Node 4.8.

I also ran command cat /etc/yum.repos.d/nodesource-el.repo to cross-check, I got below reponse

[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://rpm.nodesource.com/pub_4.x/el/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL

[nodesource-source]
name=Node.js for Enterprise Linux 7 - $basearch - Source
baseurl=https://rpm.nodesource.com/pub_4.x/el/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
gpgcheck=1

I also ran command rpm -qa 'node|npm' I got nodesource-release-el7-1.noarch

I also ran below commands and tried reinstalling my specific version but no success.

yum remove nodesource-release* nodejs
yum clean all

Any Suggestion if I am doing anything wrong?

2条回答
爷的心禁止访问
2楼-- · 2019-07-18 18:40

It's difficult to give you a answer because the problem could has more than one reasons, maybe in this link you can find more help because the problem is treated in depth.

Also I'm going to explain my solution was made months ago, I remove all the node repos:

sudo rm -fv /etc/yum.repos.d/nodesource*

After that, clean and update:

sudo yum clean all && yum update

And after that, try again to install node 4.

If you have the same error at this point, it's because you have 2 paths of nodejs, probably if you run $ which node it returns /usr/local/bin/node instead of /usr/bin/node

Then, you have two options as in the first answer in the previous link i gave says:

Option 1:

This is the easy way out. You can edit your .bashrc and add an alias that will point node -> /usr/bin/node. This is as simpple as adding alias node="/usr/bin/node". This will call the correct version everytime but I cannot guarantee that it will not cause conflicts in the future with libraries.

Option 2: This is the hard way but it will fix it. First, purge with yum nodejs installed on the system. Second, get the tarball for the version you have compile, untar it, ./configure and uninstall it. This step, you can find online easily. Finally, reinstall nodejs through yum and that should fix your problem.

查看更多
叼着烟拽天下
3楼-- · 2019-07-18 18:55

Well, to install your specific node version you need to run below command sequentially:

[root@server ~]#  yum remove nodesource-release* nodejs
[root@server ~]#  yum clean all
[root@server ~]#  cd ~
[root@server ~]#  wget https://nodejs.org/dist/latest-v4.x/node-v4.8.4-linux-x64.tar.gz

Note: Your version number in the URL is likely to be different than the one above. Use the address you copied from the Node.js site rather than the specific URL provided in this guide.

Next, we will extract the binary package into our system's local package hierarchy with the tar command. The archive is packaged within a versioned directory, which we can get rid of by passing the --strip-components 1 option. We will specify the target directory of our command with the -C command:

[root@server ~]#  sudo tar --strip-components 1 -xzvf node-v* -C /usr/local

This will install all of the components within the /usr/local branch of your system. You can verify that the installation was successful by asking Node for its version number:

[root@server ~]# node --version
v4.8.4
[root@server ~]# npm -version
2.15.11
查看更多
登录 后发表回答