Install node.js under Ubuntu

There is no doubt that ubuntu is friendly to novices. In terms of stability, centos have their own advantages.

If you are running on your own local VM, the commonly used ubuntu14.04 is recommended to download. I bought Ali's [Cloud Server] (https://cloud.tencent.com/product/cvm?from=10680) not long ago. Ubuntu only supports 16.04. Today I will reconfigure the environment.

First connect to our server, here I use the finalShell terminal connection, it is very convenient, supports copy and paste, and visualize folders.

Look at the software renderings:

(1) Organize the environment#

  1. Let's update the toolkit first to prevent future troubles:
sudo apt-get update
  1. Install the server to maintain daily dependencies (considering the use of git later, so git is installed here), execute the command
sudo apt-get install git vim openssl build-essential libssh-dev wget curl

The environment is comfortable here

(2) Install nvm and node.js

  1. Execute the following code to install nvm. The installation command can be found by searching for nvm on github.

Address: https://github.com/nvm-sh/nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.33.2/install.sh | bash
nvm ls
  1. After the installation is successful, we execute nvm ls to check the installation of nvm, the general situation is as follows:

  1. There will usually be a No Commond error. Don't be afraid. It is normal and lacks environment variables. Let's configure it next:

  2. Enter nvm installation to the file directory

 cd ~/.nvm

View the list of files in the directory ls

If there is no .bash_profile file, create and edit the file:

touch .bash_profile
vim .bash_profile

Paste the edited content directly:

export NVM_DIR="$HOME/.nvm"[-s "$NVM_DIR/nvm.sh"]&& \."$NVM_DIR/nvm.sh" # This loads nvm
[- s "$NVM_DIR/bash_completion"]&& \."$NVM_DIR/bash_completion" # This loads nvm bash_completion

Save and close this file. Update the environment changes just configured

source .bash_profile

Enter the nvm ls command to verify whether it is successful, *At this time, enter nvm ls and it is empty, as shown below: *

touch .bash_profile
vim .bash_profile

This is because the corresponding nodejs has not been installed
  1. Execute the following command to install node.jsv8.1.2
nvm install v8.1.2

( Three) test node.js#

Let’s go to the official website of node.js, here to talk about the Chinese version that is not tested, the English version’s address: https://nodejs.org/en/about/

We create a new server.js under the / directory. Copy the content

const http =require('http');const hostname ='127.0.0.1';const port =3000;const server = http.createServer((req, res)=>{
 res.statusCode =200;
 res.setHeader('Content-Type','text/plain');
 res.end('Hello World\n');});

server.listen(port, hostname,()=>{
 console.log(`Server running at http://${hostname}:${port}/`);});

Run the code through the node server, the effect diagram is as follows:

At this point, our nodejs environment is installed.

Recommended Posts

Install node.js under Ubuntu
ubuntu install nodejs
Install nodejs and npm under Ubuntu 16.04
Install apache+PHP under Ubuntu
Install python3.6 under Ubuntu 16.04
Install mysql under Ubuntu 16.04
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
Install Caffe under Ubuntu 14.04
Install nodejs10 on Ubuntu16
2018-09-11 Install arduino under Ubuntu
ubuntu16.04 install node.js, npm
Install ROS under ROS Ubuntu 18.04[2]
Install MySQL under Ubuntu
Install Yarm-PM2 under Ubuntu
Install server-side Shadowsocks under Ubuntu 16.04
Install rgl package under Ubuntu
How to install Node.js on Ubuntu 16.04
Install 3 single-cell R packages under Ubuntu
Install and deploy Gerrit under Ubuntu
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install JDK1.8 original under Ubuntu Kylin
Small tool: install screenshot tool under ubuntu
How to install Audacious under Ubuntu
How to install Tensorflow under ubuntu 16.04
Compile and install QEMU under Ubuntu
ubuntu18.04 install python2
ubuntu18.04 install docker
ubuntu12.04 install python3
Ubuntu install guide
ubuntu 16 install asp.net
ubuntu install leanote
ubuntu install Jenkins
docker install ubuntu
ubuntu install elasticsearch
ubuntu16.0.1 install pagoda
CentOS install nodejs 8
ubuntu18.04 install python
ubuntu 18.04 install teamviewer
ubuntu install sendmail
Install linux (ubuntu) dual system under windows system
Install YouCompleteMe plugin for vim under Ubuntu
Install PyTesser under ubuntu 14.04 for OCR recognition
Install Ubuntu with Parallels Desktop under Mac
Three ways to install software under Ubuntu
Install utility software collection under Ubuntu system
How to install vim editor under Linux (Ubuntu 18.04)
Install mysql-pytho in Ubuntu
ubuntu install zsh terminal
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install docker on Ubuntu
Install mysql5.7 under CentOS7
Nodejs install on centos7
Ubuntu18.04 install opencv 3.2.0 solution
Install ActiveMQ under Centos7
Python MySQLd under Ubuntu
Install Docker on ubuntu18.04
Start working under ubuntu