How to install node.js with nvm on Ubuntu


It’s recommend to use nvm

sudo apt-get update 
sudo apt-get install build-essential libssl-dev

Check nvm github to find the latest version and run command like:

curl -o- | bash

If you see “Command ‘nvm’ not found” while typing “nvm”, try to close and reopen your terminal.

If the problem still exists, check if nvm has been configured in .bash_profile (sometimes it’s been configured in .bashrc on ubuntu 16)

Check remote version:

nvm ls-remote

Check current node version:

node -v

Install a new version:

nvm install v10.12.0

Switch version:

nvm use 10.12.0

Install a module:

npm install -g hexo

It will be installed in:


Write a test script, name it as 01.js:

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});

    response.end("Hello, I'm running on port 4000!\n");

console.log('Server running at');


node 01.js

Now it can be accessed via