Manage **env with anyenv

由於現在的開發者可能需要用到多種語言來進行開發,但每次都必須安裝各個語言的**env來管理其語言的版本實在有點麻煩,不過現在有了讓大家更方便的anyenv,就不用每次都裝好幾個**env了!

按照以下步驟安裝即可。(基本上就和Readme裡一樣)

  1. Install
1
$ git clone https://github.com/riywo/anyenv ~/.anyenv
  1. Add to your .profile or .bashrc or .zshrc
1
2
3
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.your_profile
$ echo 'eval "$(anyenv init -)"' >> ~/.your_profile
$ exec $SHELL -l // this line will reload shell
  1. 接下來安裝所需要語言即可
1
2
3
4
5
$ anyenv install rbenv // ruby
$ anyenv install pyenv // python
$ anyenv install phpenv // php
$ anyenv install ndenv // node
$ anyenv install goenv // go

剛開始會指向system版本。

1
2
3
4
5
6
7
8
9
$ anyenv versions
ndenv:
* system (set by /home/cyb/.anyenv/envs/ndenv/version)
goenv:
* system (set by /home/cyb/.anyenv/envs/goenv/version)
pyenv:
* system (set by /home/cyb/.anyenv/envs/pyenv/version)
rbenv:
* system (set by /home/cyb/.anyenv/envs/rbenv/version)

安裝所需版本

1
2
3
4
5
$ rbenv install 2.1.5
$ ndenv install v0.10.33
$ pyenv install 2.7.8
$ pyenv install 3.4.2
$ goenv install 1.3

並將此版本設為global

1
2
3
4
5
$ rbenv global 2.1.5
$ ndenv global v0.10.33
$ pyenv global 2.7.8
$ pyenv global 3.4.2
$ goenv global 1.3

此時可以透過anyenv versions看到。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ anyenv versions
ndenv:
system
* v0.10.33 (set by /home/cyb/.anyenv/envs/ndenv/version)
goenv:
system
* 1.3 (set by /home/cyb/.anyenv/envs/goenv/version)
pyenv:
system
2.7.8
* 3.4.2 (set by /home/cyb/.anyenv/envs/pyenv/version)
rbenv:
system
* 2.1.5 (set by /home/cyb/.anyenv/envs/rbenv/version)

此時所需要的package manager也都一併安裝了。可透過which確認。

1
2
3
4
5
6
7
8
$ which npm
/home/cyb/.anyenv/envs/ndenv/shims/npm
$ which gem
/home/cyb/.anyenv/envs/rbenv/shims/gem
$ which bundle
/home/cyb/.anyenv/envs/rbenv/shims/bundle

Reference

rbenv, pyenv, plenv, phpenv から anyenv への移行
anyenvという**env系の簡易マネージャを作った
anyenvで開発環境を整える