9
10

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 3 years have passed since last update.

asdfを使おう

Last updated at Posted at 2021-02-12

nodenv使いからのanyenv使いになった皆様におかれましては、そろそろDenoでも触ってみるかといった頃合いかと思います。
anyenvにdenoあるやろーと思って$ anyenv install -lしたところdenoenvないやん!!?ってめんどくさくなっていませんか?
asdfにはそれがあります!

ということでasdfを使ってみました。

asdf?

nodenvはnodeのバージョンを切り替えられるツール
環境変数をごにょごにょ切り替えてくれるもので、複数のプロジェクトを横断していたりすると重宝するものですよね。
anyenv, asdfはnodeだけでなくて対応している言語のバージョンを管理できるものです。

  • anyenv, asdf で言語をローカルにインストールできる。
  • 同一言語でも複数バージョン入れておける。
  • プロジェクトディレクトリに.xxxversionのファイルを置いておくことで勝手に切り替えてくれる。

インストール

こちら。簡単
https://asdf-vm.com/#/core-manage-asdf

~/.bashrc などに追記をお忘れなく。

使うコマンド

そんなにないっす。plugin=言語のこと

$ asdf plugin list all 対応している言語のリストを表示

いっぱいあります。

$ asdf plugin add <name> 言語をインストール

$ asdf plugin add nodejs

$ asdf list all <name> 言語のバージョン一覧

0.1.14
0.1.15
0.1.16
~~snip;

$ asdf install <name> <version> 指定のバージョンを入れる

例: $ asdf install nodejs 15.8.0
ちなみにnodejsの場合はファイルのチェックサムを信用するためにPGPキーを事前に設定しておく必要があるってでる。 https://github.com/asdf-vm/asdf-nodejs

[derori@murata ~]$ asdf install nodejs 15.8.0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3811    0  3811    0     0  90738      0 --:--:-- --:--:-- --:--:-- 90738
Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting.

[derori@murata ~]$ bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'
gpg: /home/derori/.gnupg/trustdb.gpg: trustdb created
gpg: key D7062848A1AB005C: public key "Beth Griggs <bgriggs@redhat.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg: key 7434390BDBE9B9C5: public key "Colin Ihrig <cjihrig@gmail.com>" imported

~~snip;


[derori@murata ~]$ asdf install nodejs 15.8.0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3811    0  3811    0     0  82847      0 --:--:-- --:--:-- --:--:-- 84688
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 31.1M  100 31.1M    0     0  79.7M      0 --:--:-- --:--:-- --:--:-- 79.7M
node-v15.8.0-linux-x64.tar.gz: OK
[derori@murata ~]$ asdf list nodejs
  15.8.0

$ asdf [global|local] <name> <version> 使うバージョン指定

global: そのユーザー全体
local: そのディレクトリ配下

.tool-versions ってファイルができて管理される。コミットしちゃっていい。.node-versionsとかと同じ。

$ asdf update アップデート

たまアップデートしてあげて。

まとめ

anyenvと共存はおかしくなるのでどっちかだけど、新しい環境はasdf使っていこうと思います!!!!

$HOME/.asdfrclegacy_version_file = yes って書けば.node-versionsなどのファイルも見てくれるようです。https://asdf-vm.com/#/core-configuration?id=homeasdfrc

あ。denoは$ asdf plugin add deno && asdf install deno latest でおーけーよ。

ドキュメント
https://asdf-vm.com/#/core-manage-asdf

9
10
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
9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?