LoginSignup
41
43

More than 5 years have passed since last update.

Debian/Ubuntuにnodejsとyarnをinstall

Last updated at Posted at 2017-06-15

背景

一次資料にあたれ、で終わる話であって本来こんな記事は不要ですが、
ubuntu install nodejs npmみたいに検索すると上位のQiitaやblog記事のほとんどが古い手順だったため、あえて書き残します。

手順

公式サイトの手順に従うことが近道です(当たり前)。

nodejs

$curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$sudo apt-get install -y nodejs

上記で6系が入ります。
6系にしたのは現在LTS(Long-term Support)のversionだからです。
https://github.com/nodejs/LTS

最近ではTLS/https周りで初のRegressionが起こり、LTSの対応リリースがなされました。
https://github.com/nodejs/LTS/issues/193

まもなく8系がLTSになるので、その時上記も古い手順となります。
おそらくsetup_8.xに変えれば動くでしょうが、必ずQiitaやStack Overflowに頼らず公式ページを確認ください。

yarn

$curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$sudo apt-get update && sudo apt-get install yarn

解説

どちらの手順でも、apt-get前にしていることはpkg取得先mirrorの登録作業(URLと鍵の登録)です。

$less /etc/apt/sources.list
(defaultのmirrorが記載)
$ls /etc/apt/sources.list.d/
nodesource.list yarn.list
$cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_6.x trusty main
deb-src https://deb.nodesource.com/node_6.x trusty main

ちなみに自分が初めて触ったUbuntuは、会社が独自にカスタマイズしたイメージで作られたものだったので、
sources.listの中が全部会社ドメインのmirrorでした。
当然置いてあるパッケージのバージョンも古く、
sudo apt-get nodejs npmではEOLバージョンのnodejsが、npmに関してはE: Unable to locate package npmと管理さえされてませんでしたorz

41
43
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
43