0
0

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 1 year has passed since last update.

Macでgoenvやrbenvを統合して使えるanyenvを試してみる

Last updated at Posted at 2023-09-05

新しい会社の開発環境構築ドキュメントを見ると、
anyenvという、goenvやrbenvなどが統合されたバージョン管理ツールがあったので試してみる。

既存に入れていたgoenvをアンイストールする。

% goenv uninstall 1.20.3
% brew uninstall goenv
Uninstalling /opt/homebrew/Cellar/goenv/2.1.4... (327 files, 534.7KB)
% vi ~/.zshrc

下記を削除

.zshrc
echo source '/opt/homebrew/share/google-cloud-sdk/completion.zsh.inc'
echo source '/opt/homebrew/share/google-cloud-sdk/path.zsh.inc'
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"

ディレクトリも削除

% rm -rf /Users/mitsuaki.ihara/.goenv

anyenvのインストール

$ brew install anyenv
% anyenv init
# Load anyenv automatically by adding
# the following to ~/.zshrc:

eval "$(anyenv init -)"

.zshrcにも追加しておく。

% vi ~/.zshrc
.zshrc
eval "$(anyenv init -)"

シェルに再アクセスするとマニフェストがないと言うエラーが出る。

% source ~/.zshrc
ANYENV_DEFINITION_ROOT(/Users/mitsuaki.ihara/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

インストールを実行

% anyenv install --init
Manifest directory doesn't exist: /Users/mitsuaki.ihara/.config/anyenv/anyenv-install
Do you want to checkout https://github.com/anyenv/anyenv-install.git? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /Users/mitsuaki.ihara/.config/anyenv/anyenv-install...
Cloning into '/Users/mitsuaki.ihara/.config/anyenv/anyenv-install'...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 71 (delta 4), reused 4 (delta 1), pack-reused 57
Receiving objects: 100% (71/71), 13.15 KiB | 6.58 MiB/s, done.
Resolving deltas: 100% (11/11), done.

Completed!

バージョンの確認。

% anyenv --version
anyenv 1.1.5

パスを通す(これを実行しないとgoenvなどのコマンドが動かない)

% echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.zshrc

goenvをanyenv経由で取得してくる。

goenvをanyenv経由でインストールする。

% anyenv install --list | grep goenv
  goenv
% anyenv install goenv
/var/folders/vv/vmvy9fnx60j1902dcdfdrx3r0000gn/T/goenv.20230905110555.18046 ~
Cloning https://github.com/syndbg/goenv.git master to goenv...
Cloning into 'goenv'...
remote: Enumerating objects: 15663, done.
remote: Counting objects: 100% (804/804), done.
remote: Compressing objects: 100% (223/223), done.
remote: Total 15663 (delta 598), reused 678 (delta 564), pack-reused 14859
Receiving objects: 100% (15663/15663), 2.93 MiB | 4.40 MiB/s, done.
Resolving deltas: 100% (10323/10323), done.
~

Install goenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.

Goをanyenv経由のgoenv経由で再インストール。

% cat .go-version
1.20.3
% goenv install 1.20.3
Downloading go1.20.3.darwin-arm64.tar.gz...
-> go1.20.3.darwin-arm64.tar.gz
% go version
go version go1.20.3 darwin/arm64

コメント

言語ごとに◯◯envを入れていたが、統合して管理できるのは便利そう。
しばらく使ってみようと思う。

追記

下記指定でダウンロードしたGoのバージョンまでパスを通さないと、
リポジトリ内のMakefileからgo installしたツールが参照できなかった。
バージョンを切り替えるごとにパスを変えるのは疑問に思うので、他に良い設定方法があるように思えるが、
調べても分からず…。

% echo 'export PATH="$HOME/go/1.20.3/bin:$PATH"' >> ~/.zshrc
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?