LoginSignup
44

More than 5 years have passed since last update.

ndenv / nodenv で Node.js をインストールする際、同時に Yarn もインストールする方法

Last updated at Posted at 2017-02-21

TL; DR

  • ndenv / nodenv を使うと任意の Node をインストールできる
  • プラグインを使うと、ndenv install と同時に Yarn のインストールできて便利

Yarn とは ?

npm に比べて速い Node 向けのパッケージマネージャーです。

ndenv / nodenv とは ?

nvm や nodebrew などと同じ、複数バージョンの Node を容易に管理する為のツールです。

プラグインの導入方法

プラグインを使うと、ndenv を使って任意の Node をインストールした際、Yarn も一緒にインストールすることができます。別途インストールする手間が省けて大変便利です。

プラグインは Git を使ってインストールします。
(nodenv を使っている方は、ndenv を nodenv に置き換えてください。)

$ git clone https://github.com/pine/ndenv-yarn-install.git "$(ndenv root)/plugins/ndenv-yarn-install"

インストールが終わったら、シェルを再起動してインストールできているか確認します。

$ exec $SHELL -l
$ ndenv hooks install
/Users/pine/.anyenv/envs/ndenv/plugins/ndenv-yarn-install/etc/ndenv.d/install/yarn-install.bash

上記のように、 ndenv-yarn-install を含んだ何らかのパスが表示されれば正常にインストールされています。

使い方

いつものように ndenv で Node をインストールするだけで、自動で Yarn もインストールされます。

$ ndenv install v7.5.0
Downloading node-v7.5.0-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v7.5.0/node-v7.5.0-darwin-x64.tar.gz
Installing node-v7.5.0-darwin-x64...
Installed node-v7.5.0-darwin-x64 to /Users/pine/.anyenv/envs/ndenv/versions/v7.5.0

Installing Yarn...
Installed Yarn 0.20.3

まとめ

Yarn は本当に爆速なので、プラグインとセットでぜひ使ってあげて下さい。

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
44