IT

How to Install Node.js on WSL(Ubuntu)

Introduction

Firstly, I want to introduce what is Node.js. Node.js that is a JavaScript can be running on Windows, Linux, Mac, not only Web Browsers.

In this article, I’m going to show you how to install Node.js on the Windows with WSL(Ubuntu).

Installing the Distro-Stable version for Ubuntu

At the time of writing, the version is 8.10.0. This isn’t the latest version, but it’s stable version, so I recommend that you would install the version of 8.10.0 on your computer.

Before getting Node.js, you should type these commands to update your local package index. Next row is installing nodejs on your computer from the repositories with using the “sudo” command.

$ sudo apt update
$ sudo apt install nodejs

In most case, npm package is also needed to get set up with Node.js.

$ sudo apt install npm

To check the version of Node.js.

$ nodejs -v
v0.10.25

If you want to get a more latest version of Node.js, you can add the PPA(personal package Archive).

$ cd ~
$ curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh

Run the script by using “bash” command.

$ sudo bash nodesource_setup.sh

To check whether the version of Node.js is more latest version.

$ nodejs -v
v8.11.3

You need to install “build-essential” in order to some npm packages to work.

$ sudo apt install build-essential

These commands are to install NVM(Node Version Manager). NVM can control your environment and works at the level of an independent directory within your home directory.

$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
$ sudo bash install_nvm.sh

To gain access to the NVM functionality. The second row can provide it automatically.

$ source ~/.profile
$ source ~/.profile >> .bashrc

You can install isolated Node.js versions. Appeared information that is about the versions of Node.js is available to use.

$ nvm ls-remote
・・・
        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

Above information can be installed. This time, we install the version of 8.11.1.

$ nvm install 8.11.1
Downloading and installing node v8.11.1...
Downloading https://nodejs.org/dist/v8.11.1/node-v8.11.1-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!

┌────────────────────────────────────────────────────────┐
│                npm update check failed                 │
│          Try running with sudo or get access           │
│          to the local update config store via          │
│ sudo chown -R $USER:$(id -gn $USER) /home/gaku/.config │
└────────────────────────────────────────────────────────┘
Now using node v8.11.1 (npm v5.6.0)
Creating default alias: default -> 8.11.1 (-> v8.11.1)

NVM can switch to use some versions. In this case, try to use the version of 8.11.1.

$ nvm use 8.11.1

┌────────────────────────────────────────────────────────┐
│                npm update check failed                 │
│          Try running with sudo or get access           │
│          to the local update config store via          │
│ sudo chown -R $USER:$(id -gn $USER) /home/gaku/.config │
└────────────────────────────────────────────────────────┘
Now using node v8.11.1 (npm v5.6.0)

As you can see, The version of Node.js is the elected version.

$ node -v
v8.11.1

If you have multiple Node.js versions, you can see what is installed on your computer.

$ nvm ls
->      v8.11.1
         system
default -> 8.11.1 (-> v8.11.1)
node -> stable (-> v8.11.1) (default)
stable -> 8.11 (-> v8.11.1) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.3 (-> N/A)
lts/carbon -> v8.11.3 (-> N/A)

If you want to default one of the version, please type this command.

$ nvm alias default 8.11.1
default -> 8.11.1 (-> v8.11.1)

If you type this command, this version will be automatically selected when a new terminal is spawned.

$ nvm use default

┌────────────────────────────────────────────────────────┐
│                npm update check failed                 │
│          Try running with sudo or get access           │
│          to the local update config store via          │
│ sudo chown -R $USER:$(id -gn $USER) /home/gaku/.config │
└────────────────────────────────────────────────────────┘
Now using node v8.11.1 (npm v5.6.0)

 

60か国の講師陣とマンツーマン!

Pickup post

  1. 【CCENT廃止】Cisco認定試験制度変更(2020年2月24日~)
  2. 【合格体験記】AWS 認定クラウドプラクティショナーの効率的な勉強方法

Related post

  1. IT

    パソコンの選び方について【ベンチマーク選定】【2019年版】

    パソコンの選び方として、まず注目されるのが「CPU」です。「…

  2. IT

    【LPIC廃止!?】新設されたLinuC試験について

    最新情報はこちらの記事を参考https://infocloudin…

  3. AI人工知能

    人工知能について知る!【多層ネットワークの実装】

    前記事では活性化関数について学びましたが、本記事では非線形関数…

  4. IT

    【OTV(Overlay Transport Virtualization)】概要

    OTV(Overlay Transport Virtualizati…

  5. AWS

    【CCENT廃止】Cisco認定試験制度変更(2020年2月24日~)

    Cisco認定試験(CCENT,CCNA,CCNP,CCIE)が20…

  6. IT

    【L2TP(Layer 2 Tunneling Protocol)】設定

    L2TP(Layer 2 Tunneling Protocol)とは…

Comment

  1. No comments yet.

  1. No trackbacks yet.

おすすめ記事

  1. AWS Practitioner
価格満足度No1
  1. 英会話

    英語を勉強するならDMM英会話!効率的な勉強法をご紹介
  2. AWS Practitioner

    AWS

    【合格体験記】AWS 認定クラウドプラクティショナーの効率的な勉強方法
  3. 最新ニュース

    タバコの値段がまた上がる?今後のタバコ事情を紹介
  4. 海外ドラマ

    ウォーキング・デッド シーズン8【第3話の感想】エゼキエル死ぬ!?
  5. 海外ドラマ

    ウォーキング・デッド シーズン8【第2話の感想】懐かしの人と再会!
PAGE TOP