Solve the problem that Linux cannot install and uninstall Node. js normally.

Source: Internet
Author: User

Solve the problem that Linux cannot install and uninstall Node. js normally.

Preface

Node. js is an event-driven I/O server-side JavaScript environment. Based on Google's V8 engine, the V8 engine executes Javascript very quickly and performs very well. To learn about Nodejs, you must first install the environment. In the actual production environment, Node. js is generally deployed in the Linux environment.

I have never been idle since I bought VPS. I always want to make full use of it.

So I decided to install nodejs to build a web server. Now the stable version of nodejs has been updated to 8. x, so I will try to dress 8. x, I did not expect to encounter another pitfall. I have been engaged for several days. I summarized it a little and wrote my notes. I 'd like to give some reference to my friends who have encountered the same pitfalls ~

Officially recommended installation method (corresponding to the version warehouse to install Nodejs)

My operating system is 64-bit in CentOS6. I checked the official Nodejs upgrade documentation (including various supported systems) and executed the following commands for my system:

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -sudo yum -y install nodejs

Of course, you may need to use the following command to install the build tool:

sudo yum install gcc-c++ make# or: sudo yum groupinstall 'Development Tools'

For other systems, see other content in the document.

Here I encountered a pitfall (this may be rare, so the specific solution will be put at the end of the article later ). The first one above should be to silently specify the use of 8. x resources, so that this is easy to use during installation rather than the original remote warehouse of yum. I don't know if this explanation is correct.

I have tried it again. The command prompts you to execute sudo yum-y install nodejs to install nodejs8.x, but it is always installed with 6.x. is it a dependency problem? I can't find the cause, but I can only find other installation methods, so I found the second installation method.

Manually install Nodejs

Obtain the latest installation package and decompress it for installation. It may depend on Python or later.

To manually install Nodejs8.x only, run the following command:

yum install gcc-c++ openssl-develcd /usr/local/srcwget http://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gztar zxvf node-v8.9.4.tar.gz(cd into extracted folder: ex "cd node-v8.9.4.tar.gz")./configuremakemake install

If it goes well, there should be no problems. It may take a while, a little longer, and you will be prompted to install it. You can execute

node -v

To check whether it is 8.x. if so, basically the installation is complete. If it is not good, it is terrible. If it is related to Python, please check the Python installation and upgrade in Linux (still draft ).

Delete nodejs

Next let's take a look at the deletion, because you have installed a lower version and need to upgrade it. That is, you need to delete the old version first. nodejs should be backward compatible, so I didn't study it, maybe I was idle, so I would study it. If I saved multiple versions of nodejs, of course, some old functions may be abolished in the new version, causing exceptions, although the benefits of upgrading are greater than the disadvantages, you still need to consider whether to upgrade the old project environment! If you are idle and have a reason to persuade me, please leave a message below. It was too easy to delete the command.

sudo yum remove nodejs

Enter y as prompted, and press enter to delete it soon. All delete operations are exciting...

In fact, I am not so easy in the installation process, or I will not be tossing around for a few days. One is a version error, and the other is a Python upgrade. The version problem was discovered only after a lot of information was generated. It turned out to be caused by yum cache problems.

If you encounter a problem similar to mine, try the following command:

rm -f /etc/yum.repos.d/nodesource-el.repoyum clean allyum -y remove nodejsyum -y install nodejs

References

  • Official Nodejs documentation. Install Nodejs through package management
  • How to manually install Nodejs in Centos
  • The correct Nodejs version cannot be installed in the Yum warehouse (similar to the sample code just now, it is used to clear the cache, but it is not valid for me)
  • Install nodejs7.x package in CentOS but it is 6.9.5 (my effective solution)
  • How to delete Nodejs using Linux commands

Summary

So, in fact, we should try to clear the cache when the version is incorrect, and then use the official command to install it ~

I think that since the Yum repository cache is a problem, in addition to Nodejs, other packages may have similar situations. If you find that you have selected the desired version and installed the old version, it has nothing to do with dependencies. Just try clearing the cache :)

Well, the above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.