Switching from pyenv, rbenv, goenv and nvm to asdf

So, there was a time when I was only developing applications using Python. And so I found out about virtual environments. And then after a couple of months, I discovered pyenv. It also came to a time I had to work on multiple projects that uses different versions of nodejs and searched something similar so…

Switching from pyenv, rbenv, goenv and nvm to asdf

So, there used to be a time when I was most fine rising functions the usage of Python. And so I stumbled on out about virtual environments.
And then after just a few months, I stumbled on pyenv.

It additionally came to a time I had to work on more than one initiatives that makes employ of various versions of nodejs and searched something identical
so I installed nvm.

Then, I was required to work on a Ruby mission so I installed rbenv.

And since golang used to be one amongst the new shiny objects that kinda got my interest, I went on and installed goenv.

Every thing used to be elegant till I kinda felt my config.fish file got bloated and by some ability nvm used to be kinda slowing down my shell startup.

I did build some optimizations corresponding to lazy loading nvm and damaged-down a fish plugin known as fish-nvm.

And then one day, I stumbled on out about asdf-vm.

To begin with save, I was barely hesitant to set up it because it would perchance well kinda disrupt my work circulation with python initiatives since I closely employ pyenv virtualenv .

However I did feel that the benefits of the usage of asdf-vm outweighs the cons so I went forward and proceeded.

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --department v0.7.8

asdf has a rather appropriate documentation to be unbiased appropriate. Despite brew being my trail to kit manager, I selected git as my set up contrivance.
My motive is that asdf requires me so that you just can add this line in my config.fish

source (brew --prefix asdf)/asdf.fish

and the brew --prefix adsf is appropriate too sluggish in contrast with appropriate having this

source $HOME/.asdf/asdf.fish

Subsequent, for the auto completions appropriate urge this expose to your terminal:

$ mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.config/fish/completions

Restart your shell in yell that PATH modifications take intention!

You might well also checkout a more detailed documentation right here: https://asdf-vm.com/#/core-situation up-asdf-vm?identity=set up

Sooner than, my config.fish regarded something love this:

situation -gx PYENV_ROOT $HOME/.pyenv
situation -gx PYTHON_BUILD_ARIA2_OPTS "-x 10 -k 1M" 
contains $PYENV_ROOT/bin $fish_user_paths; or situation -Ua fish_user_paths $PYENV_ROOT/bin
situation --is-interactive; and pyenv init - | source
situation --is-interactive; and pyenv virtualenv-init - | source

situation -gx GOENV_GOPATH_PREFIX $HOME/.trail
situation --is-interactive; and goenv init - | source

situation --is-interactive; and rbenv init - | source

situation -gx nvm_alias_output $HOME/.node_aliases
contains $nvm_alias_output $fish_user_paths; or situation -Ua fish_user_paths $nvm_alias_output


situation -gx PYTHON_BUILD_ARIA2_OPTS "-x 10 -k 1M" 

source $HOME/.asdf/asdf.fish

As soon as more, most of the things I get right here appropriate came from the documentation: https://asdf-vm.com/#/core-situation up-plugins?identity=add

pyenv replacement

$ asdf plugin add python
$ asdf set up python most fresh:3 
$ asdf global python 3.8.4 

rbenv replacement

$ asdf plugin add ruby
$ asdf set up ruby most fresh 
$ asdf global ruby 2.7.1

goenv replacement

$ asdf plugin add golang
$ asdf set up golang most fresh 
$ asdf global golang 1.14.6

nvm replacement

$ asdf plugin add nodejs
$ asdf set up nodejs 12.18.2
$ asdf global nodejs 12.18.2

The usage of asdf global creates a file below your HOME list known as .intention-versions

$ cat ~/.intention-versions
python 3.8.4
ruby 2.7.1
golang 1.14.6
nodejs 12.18.2

This lets asdf know which versions to employ. And obviously, in distinction to global,
there might perchance be additionally the local keyword that creates one other .intention-versions.
Here’s devoted when initiatives require various version.

$ cd ~/project1
$ asdf local python 3.7.5
$ python --version 
$ cd ~/project2
$ python --version 

asdf has deal of plugins in the market. You might well also test them out right here: https://github.com/asdf-vm/asdf-plugins

In notify to accommodate my work circulation when I was peaceable the usage of pyenv virtualenv,
I created a purpose that behaves barely an much like pyenv virtualenv.

$ touch ~/.config/fish/functions/venv.fish

And paste the following:

purpose venv --argument-names 'python_version' --description 'Do virtualenv named the identical as contemporary list'
  situation -l python_bin

  if no longer test -n "$python_version"
    situation python_bin ($HOME/.asdf/bin/asdf which python)
    situation python_bin $ASDF_DIR/installs/python/$python_version/bin/python

  situation -l venv_name (basename $PWD | tr . -)

  if no longer test -e $python_bin
    echo "Python version `$python_version` just isn't any longer installed."
    return 1

  echo Growing virtualenv `$venv_name`
  $python_bin -m venv $HOME/.virtualenvs/$venv_name
  source $HOME/.virtualenvs/$venv_name/bin/activate.fish

Whenever I’m interior a python mission, I appropriate want to form venv or venv
and this would perchance automatically create a virtualenv below ~/.virtualenvs the usage of the contemporary list title.

In notify to automatically activate the virtualenv when cding to a mission, build the following:

$ touch ~/.config/fish/conf.d/__auto_venv.fish

And paste the following:

purpose __auto_venv --on-variable PWD --description "Mechanically activate python venv"
  situation -l venv_name (basename $PWD | tr . -)

  if test -d $HOME/.virtualenvs/$venv_name
    source $HOME/.virtualenvs/$venv_name/bin/activate.fish

Wintry! Now not most fine did I minimize the traces in my config.fish, I would perchance well additionally see a reduced startup time which is a appropriate whisper!

You might well also additionally test out my dotfiles in my GitHub repository: https://github.com/yujinyuz/dotfiles

I hope this article helped you! You might well also trail away a comment below and I’ll strive to acknowledge to them as rapid as I will.

Thanks for reading! 🎉

Read More
Portion this on knowasiak.com to test with other folks on this topicTicket up on Knowasiak.com now can have to you are no longer registered but.



Hey! look, i give tutorials to all my users and i help them!Bio: About: