LoginSignup
28
24

More than 3 years have passed since last update.

fishターミナルでanyenvとndenvをインストールする。

Last updated at Posted at 2017-12-23

fishターミナルでanyenvとndenvをインストールする。

Node.jsのバージョンを自動で切り替えられるndenvが超便利の記事を読んでインストールをしたのでその備忘録
ターミナルがfishだったので以下fish版のndenvインストール手順です。
もしかしたら手順漏れがあるかもしれません。その場合編集リクエスト下さい。

anyenvとは

anyenvとは公式にanyenv - all in one for **envとあるように何かしらのenvをインストールすることができるツールです。詳しくは公式を見ましょう。bashだとインストール手順は簡単です。

ndenvとは

2019/11/28 追加
公式ではndenvではなく、nodenvを推奨しています。
[Deprecated] nodenv is better alternative

ndenvとは公式にndenv - another node.js/io.js version managerとあるようにnodejsを管理するためのツールです。nodejsのインストールにnodebrewを利用してる方は多いとも思います。しかし、nodebrewだとプロジェクトごとにnodebrew use vx.x.xのように切り替える必要があります。
ndenvを利用すればnodeのバージョンをプロジェクトごとに自動で切り替えることができます。
詳しくは公式を見ましょう。anyenvを利用しない方法のインストールはbashだと手順が簡単です。

anyenvをインストール

ndenvをインストールするためにまずは、anyenvを用意します。

anyenvを取得
$ git clone https://github.com/riywo/anyenv ~/.anyenv

~/.config/fish/config.fishを編集してanyenvのパスを通します。

~/.config/fish/config.fishにPATHを通す
$ vim ~/.config/fish/config.fish

この一文を貼り付けます。
set -x PATH $HOME/.anyenv/bin $PATH

$ source ~/.config/fish/config.fish
$ anyenv
anyenv
Usage: anyenv <command> [<args>]

Some useful anyenv commands are:
   commands            List all available anyenv commands
   local               Show the local application-specific Any version
   global              Show the global Any version
   install             Install a **env
   uninstall           Uninstall a specific **anv
   version             Show the current Any version and its origin
   versions            List all Any versions available to **env

See `anyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/riywo/anyenv#readme

anyenvのインストールができました。

ndenvのインストール

ndenvはanyenvからインストールします。

ndenvをインストール
$ anyenv install ndenv

ndenvのパスの場所はanyenv init -を実行すると確認することができます。
一部$HOMEに置換しています。


$ anyenv init -
source "$HOME/.anyenv/libexec/../completions/anyenv.fish"
function anyenv
  set command $argv[1]
  set -e argv[1]

  command anyenv "$command" $argv
end
set -x NDENV_ROOT "$HOME/.anyenv/envs/ndenv"
set -x PATH $PATH "$HOME/.anyenv/envs/ndenv/bin"
export PATH="$HOME/.anyenv/envs/ndenv/shims:${PATH}"
ndenv rehash 2>/dev/null
ndenv() {
  typeset command
  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "`ndenv "sh-$command" "$@"`";;
  *)
    command ndenv "$command" "$@";;
  esac
}
~/.config/fish/config.fishにPATHを通す
$ vim ~/.config/fish/config.fish

~/.config/fish/config.fishを編集してndenvのパスを通します。
anyenv init -の実行結果からndenvのROOTPATHとPATHを通すためのコマンドをコピーします。

ndenvを利用するために通すPATH
set -x NDENV_ROOT $HOME/.anyenv/envs/ndenv
set -x PATH $HOME/.anyenv/envs/ndenv/bin $PATH
set -x PATH $NDENV_ROOT/shims $PATH
$ source ~/.config/fish/config.fish
$ ndenv
ndenv 0.4.0-4-ga339097
Usage: ndenv <command> [<args>]

Some useful ndenv commands are:
   commands    List all available ndenv commands
   local       Set or show the local application-specific Node version
   global      Set or show the global Node version
   shell       Set or show the shell-specific Node version
   install     Install a Node version using the node-build plugin
   uninstall   Uninstall a specific Node version
   rehash      Rehash ndenv shims (run this after installing executables)
   version     Show the current Node version and its origin
   versions    List all Node versions available to ndenv
   which       Display the full path to an executable
   whence      List all Node versions that contain the given executable

See `ndenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/riywo/ndenv#readme

ndenvのインストールができました。

ndenvを使ってみる

$ ndenv install v8.9.3
$ ndenv global v8.9.3
$ ndenv local v8.9.3
$ ls
.node-version

.node-versionがあればOKです。

$ node -v
v8.9.3

もし、バージョンが変わらない場合はbrewnodeをアンインストールして下さい。
方法はNodebrew本体を削除する方法がわかりやすいです。

28
24
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
28
24