Node.js is a software platform that transforms JavaScript from a highly specialized language into a general-purpose language. Node.js adds the ability for JavaScript to interact with input/output devices via its API (written in C++), to connect other external libraries written in different languages, providing calls to them from JavaScript code. Node.js is used primarily on the server, acting as a web server, but there is an opportunity to develop in Node.js and desktop window applications (using NW.js, AppJS or Electron for Linux, Windows and Mac OS)

    file

    Installing a version of the distribution from the standard repositories.

    To install it we will use the package manager apt

    First update the local package index, and then install the distribution from the repositories:

    sudo apt-get update  
    

    Next, let's install Node.js from the repositories:

    sudo apt-get install nodejs  
    

    Let's install npm - package manager for Node.js

    sudo apt-get install npm  
    

    This will allow you to install modules and packages for Node.js.
    Due to a conflict with another package, the executable from Ubuntu repositories is called nodejs instead of node

    To check the version of Node.js you have installed, run the command:

    nodejs -v  
    
    [email protected]:~# nodejs -v  
    v4.2.6  
    

    Installing with PPA

    Using the personal package archive (PPA) supported by NodeSource, you can choose to install between Node.js v8.x (supported until December 2019), Node.js v10.x (supported until April 2021) and Node.js v12.x.

    First, you need to install the PPA itself to access its contents

    Make sure you are in your home directory

    cd ~  
    

    Then use curl to get the installation script for the version you need, replacing 10.x with the version you need:

    curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh  
    

    You can view the contents of the script with the nano editor:

    nano nodesource_setup.sh  
    
    #!/bin/bash
    
    # Discussion, issues and change requests at:
    # https://github.com/nodesource/distributions
    #
    # Script to install the NodeSource Node.js 10.x repo onto a
    # Debian or Ubuntu system.
    #
    # Run as root or insert `sudo -E` before `bash`:
    #
    # curl -sL https://deb.nodesource.com/setup_10.x | bash -
    # or
    # wget -qO- https://deb.nodesource.com/setup_10.x | bash -
    #
    # CONTRIBUTIONS TO THIS SCRIPT
    #
    # This script is built from a template in
    # https://github.com/nodesource/distributions/tree/master/deb/src
    # please don't submit pull requests against the built scripts.
    #
    
    
    export DEBIAN_FRONTEND=noninteractive  
    SCRSUFFIX="_10.x"  
    NODENAME="Node.js 10.x"  
    NODEREPO="node_10.x"  
    NODEPKG="nodejs"  
    
    print_status() {  
        echo
        echo "## $1"
        echo
    }
    
    if test -t 1; then # if terminal  
        ncolors=$(which tput > /dev/null && tput colors) # supports colors
        if test -n "$ncolors" && test $ncolors -ge 8; then
            termcols=$(tput cols)
            bold="$(tput bold)"
            underline="$(tput smul)"
            standout="$(tput smso)"
            normal="$(tput sgr0)"
            black="$(tput setaf 0)"
            red="$(tput setaf 1)"
            green="$(tput setaf 2)"
            yellow="$(tput setaf 3)"
            blue="$(tput setaf 4)"
            magenta="$(tput setaf 5)"
            cyan="$(tput setaf 6)"
            white="$(tput setaf 7)"
        fi
    
    

    Run the script with sudo privileges:

    sudo bash nodesource_setup.sh  
    

    The PPA will be included in the configuration
    After running the installation script from Nodesource, you can install Node.js in the same way as described earlier:

    sudo apt-get install nodejs  
    

    To check which version of Node.js is which, run the command:

    nodejs -v  
    
    [email protected]:~# nodejs -v  
    v10.20.1  
    

    The nodejs package contains both nodejs and npm, so there is no need to install npm additionally .

    npm uses a configuration file in your home directory to track updates. This file will be created the first time you run npm

    To make sure npm is installed, run the following command:

    npm -v  
    
    [email protected]:~# npm -v  
    6.14.4  
    

    Some packages from npm (such as those that require compilation from source) will require the build-essentials package to work:

    sudo apt-get install build-essential  
    
    [email protected]:~# sudo apt-get install build-essential  
    Reading package lists... Done  
    Building dependency tree  
    Reading state information... Done  
    build-essential is already the newest version (12.1ubuntu2).  
    build-essential set to manually installed.  
    The following packages were automatically installed and are no longer required:  
      gyp libjs-inherits libjs-node-uuid libllvm3.8 libmircommon5 libuv1 libuv1-dev
      linux-headers-4.4.0-57 linux-headers-4.4.0-57-generic linux-headers-4.4.0-59
      linux-headers-4.4.0-59-generic linux-image-4.4.0-57-generic linux-image-4.4.0-59-generic
      node-abbrev node-ansi node-ansi-color-table node-archy node-async node-block-stream
      node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent node-form-data
      node-fstream node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs
      node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile node-lru-cache
      node-mime node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt
      node-normalize-package-data node-npmlog node-once node-osenv node-qs node-read
      node-read-package-json node-request node-retry node-rimraf node-semver node-sha
      node-sigmund node-slide node-tar node-tunnel-agent node-underscore node-which
      python-pkg-resources
    Use 'sudo apt autoremove' to remove them.  
    0 upgraded, 0 newly installed, 0 to remove and 299 not upgraded.
    
    

    Installing Node.js with nvm

    You can also install Node.js using the nvm version manager.

    The nvm manager allows you to install multiple full versions of Node.js on the same server. You will be able to choose the version that best suits each application.

    First, you need to install packages to compile the source code from the Ubuntu repositories. The nvm script will use them to build the programs.

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

    You can use curl to download the install script nvm from the project page on GitHub
    Note that the version number may be different than this example:

    curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh  
    

    You can view the install script using nano:

    nano install_nvm.sh  
    
    #!/usr/bin/env bash
    
    { # this ensures the entire script is downloaded #
    
    nvm_has() {  
      type "$1" > /dev/null 2>&1
    }
    
    nvm_default_install_dir() {  
      [ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nv$
    }
    
    nvm_install_dir() {  
      if [ -n "$NVM_DIR" ]; then
        printf %s "${NVM_DIR}"
      else
        nvm_default_install_dir
      fi
    }
    
    nvm_latest_version() {  
      echo "v0.35.3"
    }
    
    nvm_profile_is_bash_or_zsh() {  
      local TEST_PROFILE
      TEST_PROFILE="${1-}"
      case "${TEST_PROFILE-}" in
        *"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
          return
        ;;
        *)
          return 1
        ;;
      esac
    }
    
    #
    # Outputs the location to NVM depending on:
    # # The availability of $NVM_SOURCE
    # # The method used ("script" or "git" in the script, defaults to "git")
    # NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
    #
    nvm_source() {  
      local NVM_METHOD
      NVM_METHOD="$1"
      local NVM_SOURCE_URL
      NVM_SOURCE_URL="$NVM_SOURCE"
      if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
        NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm-exe$
      elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
    

    Run the script in bash:

    bash install_nvm.sh  
    

    This command will install the software in the ~/.nvm subdirectory of your home directory. It will also add some necessary settings to the ~/.profile file.

    To access nvm, you have to log out and log back in. You can also use the command:

    source ~/.profile  
    

    Manager is installed, you can start installing isolated versions of Node.js.
    To get a list of available versions of Node.js, type:

    nvm ls-remote  
    

    Output

    [email protected]:~# nvm ls-remote  
            v0.1.14
            v0.1.15
            v0.1.16
            v0.1.17
            v0.1.18
            v0.1.19
            v0.1.20
            v0.1.21
            v0.1.22
            v0.1.23
            v0.1.24
            v0.1.25
            v0.1.26
            v0.1.27
            v0.1.28
            v0.1.29
            v0.1.30
            v0.1.31
            v0.1.32
            v0.1.33
            v0.1.90
            v0.1.91
            v0.1.92
            v0.1.93
            v0.1.94
            v0.1.95
            v0.1.96
            v0.1.97
            v0.1.98
            v0.1.99
           v0.1.100
           v0.1.101
           v0.1.102
           v0.1.103
           v0.1.104
             v0.2.0
             v0.2.1
             v0.2.2
             v0.2.3
             v0.2.4
             v0.2.5
             v0.2.6
             v0.3.0
             v0.3.1
             v0.3.2
             v0.3.3
             v0.3.4
             v0.3.5
             v0.3.6
             v0.3.7
             v0.3.8
             v0.4.0
             v0.4.1
             v0.4.2
             v0.4.3
             v0.4.4
             v0.4.5
             v0.4.6
             v0.4.7
             v0.4.8
             v0.4.9
            v0.4.10
            v0.4.11
            v0.4.12
             v0.5.0
             v0.5.1
             v0.5.2
             v0.5.3
             v0.5.4
             v0.5.5
             v0.5.6
             v0.5.7
             v0.5.8
             v0.5.9
            v0.5.10
             v0.6.0
             v0.6.1
             v0.6.2
             v0.6.3
             v0.6.4
             v0.6.5
             v0.6.6
             v0.6.7
             v0.6.8
             v0.6.9
            v0.6.10
            v0.6.11
            v0.6.12
            v0.6.13
            v0.6.14
            v0.6.15
            v0.6.16
            v0.6.17
            v0.6.18
            v0.6.19
            v0.6.20
            v0.6.21
             v0.7.0
             v0.7.1
             v0.7.2
             v0.7.3
             v0.7.4
             v0.7.5
             v0.7.6
             v0.7.7
             v0.7.8
             v0.7.9
            v0.7.10
            v0.7.11
            v0.7.12
             v0.8.0
             v0.8.1
             v0.8.2
             v0.8.3
             v0.8.4
             v0.8.5
             v0.8.6
             v0.8.7
             v0.8.8
             v0.8.9
            v0.8.10
            v0.8.11
            v0.8.12
            v0.8.13
            v0.8.14
            v0.8.15
            v0.8.16
            v0.8.17
            v0.8.18
            v0.8.19
            v0.8.20
            v0.8.21
            v0.8.22
            v0.8.23
            v0.8.24
            v0.8.25
            v0.8.26
            v0.8.27
            v0.8.28
             v0.9.0
             v0.9.1
             v0.9.2
             v0.9.3
             v0.9.4
             v0.9.5
             v0.9.6
             v0.9.7
             v0.9.8
             v0.9.9
            v0.9.10
            v0.9.11
            v0.9.12
            v0.10.0
            v0.10.1
            v0.10.2
            v0.10.3
            v0.10.4
            v0.10.5
            v0.10.6
            v0.10.7
            v0.10.8
            v0.10.9
           v0.10.10
           v0.10.11
           v0.10.12
           v0.10.13
           v0.10.14
           v0.10.15
           v0.10.16
           v0.10.17
           v0.10.18
           v0.10.19
           v0.10.20
           v0.10.21
           v0.10.22
           v0.10.23
           v0.10.24
           v0.10.25
           v0.10.26
           v0.10.27
           v0.10.28
           v0.10.29
           v0.10.30
           v0.10.31
           v0.10.32
           v0.10.33
           v0.10.34
           v0.10.35
           v0.10.36
           v0.10.37
           v0.10.38
           v0.10.39
           v0.10.40
           v0.10.41
           v0.10.42
           v0.10.43
           v0.10.44
           v0.10.45
           v0.10.46
           v0.10.47
           v0.10.48
            v0.11.0
            v0.11.1
            v0.11.2
            v0.11.3
            v0.11.4
            v0.11.5
            v0.11.6
            v0.11.7
            v0.11.8
            v0.11.9
           v0.11.10
           v0.11.11
           v0.11.12
           v0.11.13
           v0.11.14
           v0.11.15
           v0.11.16
            v0.12.0
            v0.12.1
            v0.12.2
            v0.12.3
            v0.12.4
            v0.12.5
            v0.12.6
            v0.12.7
            v0.12.8
            v0.12.9
           v0.12.10
           v0.12.11
           v0.12.12
           v0.12.13
           v0.12.14
           v0.12.15
           v0.12.16
           v0.12.17
           v0.12.18
        iojs-v1.0.0
        iojs-v1.0.1
        iojs-v1.0.2
        iojs-v1.0.3
        iojs-v1.0.4
        iojs-v1.1.0
        iojs-v1.2.0
        iojs-v1.3.0
        iojs-v1.4.1
        iojs-v1.4.2
        iojs-v1.4.3
        iojs-v1.5.0
        iojs-v1.5.1
        iojs-v1.6.0
        iojs-v1.6.1
        iojs-v1.6.2
        iojs-v1.6.3
        iojs-v1.6.4
        iojs-v1.7.1
        iojs-v1.8.1
        iojs-v1.8.2
        iojs-v1.8.3
        iojs-v1.8.4
        iojs-v2.0.0
        iojs-v2.0.1
        iojs-v2.0.2
        iojs-v2.1.0
        iojs-v2.2.0
        iojs-v2.2.1
        iojs-v2.3.0
        iojs-v2.3.1
        iojs-v2.3.2
        iojs-v2.3.3
        iojs-v2.3.4
        iojs-v2.4.0
        iojs-v2.5.0
        iojs-v3.0.0
        iojs-v3.1.0
        iojs-v3.2.0
        iojs-v3.3.0
        iojs-v3.3.1
             v4.0.0
             v4.1.0
             v4.1.1
             v4.1.2
             v4.2.0 (LTS: Argon)
             v4.2.1 (LTS: Argon)
             v4.2.2 (LTS: Argon)
             v4.2.3 (LTS: Argon)
             v4.2.4 (LTS: Argon)
             v4.2.5 (LTS: Argon)
             v4.2.6 (LTS: Argon)
             v4.3.0 (LTS: Argon)
             v4.3.1 (LTS: Argon)
             v4.3.2 (LTS: Argon)
             v4.4.0 (LTS: Argon)
             v4.4.1 (LTS: Argon)
             v4.4.2 (LTS: Argon)
             v4.4.3 (LTS: Argon)
             v4.4.4 (LTS: Argon)
             v4.4.5 (LTS: Argon)
             v4.4.6 (LTS: Argon)
             v4.4.7 (LTS: Argon)
             v4.5.0 (LTS: Argon)
             v4.6.0 (LTS: Argon)
             v4.6.1 (LTS: Argon)
             v4.6.2 (LTS: Argon)
             v4.7.0 (LTS: Argon)
             v4.7.1 (LTS: Argon)
             v4.7.2 (LTS: Argon)
             v4.7.3 (LTS: Argon)
             v4.8.0 (LTS: Argon)
             v4.8.1 (LTS: Argon)
             v4.8.2 (LTS: Argon)
             v4.8.3 (LTS: Argon)
             v4.8.4 (LTS: Argon)
             v4.8.5 (LTS: Argon)
             v4.8.6 (LTS: Argon)
             v4.8.7 (LTS: Argon)
             v4.9.0 (LTS: Argon)
             v4.9.1 (Latest LTS: Argon)
             v5.0.0
             v5.1.0
             v5.1.1
             v5.2.0
             v5.3.0
             v5.4.0
             v5.4.1
             v5.5.0
             v5.6.0
             v5.7.0
             v5.7.1
             v5.8.0
             v5.9.0
             v5.9.1
            v5.10.0
            v5.10.1
            v5.11.0
            v5.11.1
            v5.12.0
             v6.0.0
             v6.1.0
             v6.2.0
             v6.2.1
             v6.2.2
             v6.3.0
             v6.3.1
             v6.4.0
             v6.5.0
             v6.6.0
             v6.7.0
             v6.8.0
             v6.8.1
             v6.9.0 (LTS: Boron)
             v6.9.1 (LTS: Boron)
             v6.9.2 (LTS: Boron)
             v6.9.3 (LTS: Boron)
             v6.9.4 (LTS: Boron)
             v6.9.5 (LTS: Boron)
            v6.10.0 (LTS: Boron)
            v6.10.1 (LTS: Boron)
            v6.10.2 (LTS: Boron)
            v6.10.3 (LTS: Boron)
            v6.11.0 (LTS: Boron)
            v6.11.1 (LTS: Boron)
            v6.11.2 (LTS: Boron)
            v6.11.3 (LTS: Boron)
            v6.11.4 (LTS: Boron)
            v6.11.5 (LTS: Boron)
            v6.12.0 (LTS: Boron)
            v6.12.1 (LTS: Boron)
            v6.12.2 (LTS: Boron)
            v6.12.3 (LTS: Boron)
            v6.13.0 (LTS: Boron)
            v6.13.1 (LTS: Boron)
            v6.14.0 (LTS: Boron)
            v6.14.1 (LTS: Boron)
            v6.14.2 (LTS: Boron)
            v6.14.3 (LTS: Boron)
            v6.14.4 (LTS: Boron)
            v6.15.0 (LTS: Boron)
            v6.15.1 (LTS: Boron)
            v6.16.0 (LTS: Boron)
            v6.17.0 (LTS: Boron)
            v6.17.1 (Latest LTS: Boron)
             v7.0.0
             v7.1.0
             v7.2.0
             v7.2.1
             v7.3.0
             v7.4.0
             v7.5.0
             v7.6.0
             v7.7.0
             v7.7.1
             v7.7.2
             v7.7.3
             v7.7.4
             v7.8.0
             v7.9.0
            v7.10.0
            v7.10.1
             v8.0.0
             v8.1.0
             v8.1.1
             v8.1.2
             v8.1.3
             v8.1.4
             v8.2.0
             v8.2.1
             v8.3.0
             v8.4.0
             v8.5.0
             v8.6.0
             v8.7.0
             v8.8.0
             v8.8.1
             v8.9.0 (LTS: Carbon)
             v8.9.1 (LTS: Carbon)
             v8.9.2 (LTS: Carbon)
             v8.9.3 (LTS: Carbon)
             v8.9.4 (LTS: Carbon)
            v8.10.0 (LTS: Carbon)
            v8.11.0 (LTS: Carbon)
            v8.11.1 (LTS: Carbon)
            v8.11.2 (LTS: Carbon)
            v8.11.3 (LTS: Carbon)
            v8.11.4 (LTS: Carbon)
            v8.12.0 (LTS: Carbon)
            v8.13.0 (LTS: Carbon)
            v8.14.0 (LTS: Carbon)
            v8.14.1 (LTS: Carbon)
            v8.15.0 (LTS: Carbon)
            v8.15.1 (LTS: Carbon)
            v8.16.0 (LTS: Carbon)
            v8.16.1 (LTS: Carbon)
            v8.16.2 (LTS: Carbon)
            v8.17.0 (Latest LTS: Carbon)
             v9.0.0
             v9.1.0
             v9.2.0
             v9.2.1
             v9.3.0
             v9.4.0
             v9.5.0
             v9.6.0
             v9.6.1
             v9.7.0
             v9.7.1
             v9.8.0
             v9.9.0
            v9.10.0
            v9.10.1
            v9.11.0
            v9.11.1
            v9.11.2
            v10.0.0
            v10.1.0
            v10.2.0
            v10.2.1
            v10.3.0
            v10.4.0
            v10.4.1
            v10.5.0
            v10.6.0
            v10.7.0
            v10.8.0
            v10.9.0
           v10.10.0
           v10.11.0
           v10.12.0
           v10.13.0 (LTS: Dubnium)
           v10.14.0 (LTS: Dubnium)
           v10.14.1 (LTS: Dubnium)
           v10.14.2 (LTS: Dubnium)
           v10.15.0 (LTS: Dubnium)
           v10.15.1 (LTS: Dubnium)
           v10.15.2 (LTS: Dubnium)
           v10.15.3 (LTS: Dubnium)
           v10.16.0 (LTS: Dubnium)
           v10.16.1 (LTS: Dubnium)
           v10.16.2 (LTS: Dubnium)
           v10.16.3 (LTS: Dubnium)
           v10.17.0 (LTS: Dubnium)
           v10.18.0 (LTS: Dubnium)
           v10.18.1 (LTS: Dubnium)
           v10.19.0 (LTS: Dubnium)
           v10.20.0 (LTS: Dubnium)
           v10.20.1 (Latest LTS: Dubnium)
            v11.0.0
            v11.1.0
            v11.2.0
            v11.3.0
            v11.4.0
            v11.5.0
            v11.6.0
            v11.7.0
            v11.8.0
            v11.9.0
           v11.10.0
           v11.10.1
           v11.11.0
           v11.12.0
           v11.13.0
           v11.14.0
           v11.15.0
            v12.0.0
            v12.1.0
            v12.2.0
            v12.3.0
            v12.3.1
            v12.4.0
            v12.5.0
            v12.6.0
            v12.7.0
            v12.8.0
            v12.8.1
            v12.9.0
            v12.9.1
           v12.10.0
           v12.11.0
           v12.11.1
           v12.12.0
           v12.13.0 (LTS: Erbium)
           v12.13.1 (LTS: Erbium)
           v12.14.0 (LTS: Erbium)
           v12.14.1 (LTS: Erbium)
           v12.15.0 (LTS: Erbium)
           v12.16.0 (LTS: Erbium)
           v12.16.1 (LTS: Erbium)
           v12.16.2 (LTS: Erbium)
           v12.16.3 (Latest LTS: Erbium)
            v13.0.0
            v13.0.1
            v13.1.0
            v13.2.0
            v13.3.0
            v13.4.0
            v13.5.0
            v13.6.0
            v13.7.0
            v13.8.0
            v13.9.0
           v13.10.0
           v13.10.1
           v13.11.0
           v13.12.0
           v13.13.0
           v13.14.0
            v14.0.0
            v14.1.0
            v14.2.0
    
    

    To install the correct version, type:

    nvm install 12.16.3  
    

    By default, it uses the most recently installed version

    When you install Node.js using nvm, the executable is named node. To find out which version of Node.js is currently in use, type:
    Normally, nvm will switch to use the most recently installed version. You can tell nvm to use the version you just downloaded explicitly as follows:

    nvm use 10.20.1  
    

    If you install Node.js via nvm, the executable will be named node. To see what version the shell is currently using, you can use the command:

    node -v  
    
    [email protected]:~# node -v  
    v12.16.3  
    

    If you have more than one version of Node.js installed, you can see their list by using the command:

    nvm ls  
    

    If you want to set one of the versions as the default version, type:

    nvm alias default 10.20.1  
    

    This version will be automatically chosen when you start a new session. You can also refer to it by alias as follows:

    nvm use default  
    
    [email protected]:~# nvm ls  
    ->     v10.20.1
             system
    default -> 10.20.1 (-> v10.20.1)  
    node -> stable (-> v10.20.1) (default)  
    stable -> 10.20 (-> v10.20.1) (default)  
    iojs -> N/A (default)  
    unstable -> N/A (default)  
    lts/* -> lts/erbium (-> N/A)  
    lts/argon -> v4.9.1 (-> N/A)  
    lts/boron -> v6.17.1 (-> N/A)  
    lts/carbon -> v8.17.0 (-> N/A)  
    lts/dubnium -> v10.20.1  
    lts/erbium -> v12.16.3 
    
    

    Each version of Node.js has its own packages which can be managed using npm.

    npm can install packages in the directory ./node_modules of Node.js projects.


    You can also use our One-Click-Apps for one-click installation of Node.js
    To do this, select the required [VPS] plan(https://fornex.com/ssd-vps) and select Apps → Node.JS version 10 or 12, to install.
    Please note that Node.js will be installed on Ubuntu 18.04.

    file


    If you have difficulty setting up or have additional questions, you can always contact our support team via ticket system.