5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nodebrewで最新のLTSをインストールする

5
Last updated at Posted at 2017-10-31

node.jsのv8.9.0(LTS)がリリースされました。

nvmを使っている人は、

$ nvm i --lts

でインストールできるらしいです(https://github.com/creationix/nvm#long-term-support )。素敵です。

でも自分はnodebrew派なのでnodebrewでLTSインストールができるか調べてみました。

結論としては、そんなオプションはありません。悔しい。
参考:https://github.com/hokaccha/nodebrew/issues/47

こっちで「https://nodejs.org/download/release/index.json のバージョンリストにltsフラグが立ってるからパースしてよ」て提案があったので、jqでパースしてみました。

(2020/09/26) @yousan さんの改善提案を受けて、記載も修正しました。

$ curl -s https://nodejs.org/download/release/index.json | jq -r 'map(select(.lts != false)) | .[].version' | sort -V | tail -1

まずcurlでバージョンリストを取ってきて、先頭が最新になるように並べ直して(もともとそうなんだろうけど念のため)、次に jq で ltsプロパティがfalseじゃない(LTSのコードネーム、ArgonとかBoronとかCarbonとか書いてある)もののバージョン番号だけを抽出し、最後に sort でバージョン番号として並び替え、最新最初の一つのバージョン番号を出力しています。

# 今8系のLTSが出た状態で、この後に6系のLTSのアップデートがリリースされると、日付でソートすると6系が先頭に来るので、意図しないバージョンが取れてしまうかもしれません。 最新の LTS だけが取れるようになりました。

ちょっと長いので、エイリアスにした方がいいかもしれません。

$ alias nodelts="curl -s https://nodejs.org/download/release/index.json | jq -r 'map(select(.lts != false)) | .[].version' | sort -V | tail -1"
$ nodelts
v8.9.0

nodebrewと組み合わせるとこんな感じでしょうか。

$ # ソースから
$ nodebrew install $(curl -s https://nodejs.org/download/release/index.json | jq -r 'map(select(.lts != false)) | .[].version' | sort -V | tail -1)
$ # エイリアス版
$ # nodebrew install $(nodelts)
$ # バイナリを直接
$ nodebrew install-binary $(curl -s https://nodejs.org/download/release/index.json | jq -r 'map(select(.lts != false)) | .[].version' | sort -V | tail -1
$ # エイリアス版
$ # nodebrew install-binary $(nodelts)
5
1
1

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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?