DEV Community

Michelle Loh
Michelle Loh

Posted on • Updated on

Install asdf (ruby, nodejs and yarn) in WSL2

What is WSL2

Read Microsoft WSL2 Documentation

What is asdf

Read asdf virtual manager Documentation

Install WSL2

Video Reference: WSL 2: Getting started (Watch from Overview until PowerShell Commands (0:00 - 8.23))

Before installing asdf

  • In your Ubuntu, type code . to open up Visual Studio Code (VS Code)
  • Open your terminal in VS Code
  • In your terminal, it should be in already be Linux not Windows (You are in Windows if you have something like PS C:\Users\>), go to linux by typing wsl
$ PS C:\Users\>wsl

# Go to root directory
$ <user_name>: cd /
Enter fullscreen mode Exit fullscreen mode
  • Do the following to get dependencies for wsl2 (else you might get the error when install ruby: BUILD FAILED (Ubuntu 20.04 using ruby-build 20210804))

For more information related to solving this problem: read here

$ sudo apt-get update
$ sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses-dev libffi-dev libgdbm-dev
Enter fullscreen mode Exit fullscreen mode

Install asdf

$ sudo apt install curl git
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
Enter fullscreen mode Exit fullscreen mode
  • Add . $HOME/.asdf/asdf.sh and . $HOME/.asdf/completions/asdf.bash in the end of .bashrc file
  • Call code ~/.bashrc in your terminal

Close and refresh terminal

  • Close your terminal by clicking the rubbish bin icon
  • Reopen the terminal

Add plugins

$ asdf plugin add ruby
$ asdf plugin add nodejs
$ asdf plugin add yarn
Enter fullscreen mode Exit fullscreen mode

Install language

  • Install ruby, nodejs and yarn latest version (or you can specify the version needed)
$ asdf install ruby latest
$ asdf install nodejs latest
$ asdf install yarn latest
Enter fullscreen mode Exit fullscreen mode
  • Check the version installed (the versions mentioned here is the latest version I downloaded)
$ asdf list
nodejs
  16.8.0
ruby
  3.0.2
yarn
  1.22.11
Enter fullscreen mode Exit fullscreen mode
  • Add to your shell
$ asdf shell ruby 3.0.2
$ asdf shell nodejs 16.8.0
$ asdf shell yarn 1.22.11
Enter fullscreen mode Exit fullscreen mode
  • Add to global
$ asdf global ruby 3.0.2
$ asdf global nodejs 16.8.0
$ asdf global yarn 1.22.11
Enter fullscreen mode Exit fullscreen mode

Install gems

  • Check where is languages installed
$ type -a ruby
ruby is /home/<user>/.asdf/shims/ruby

$ type -a node
node is /home/<user>/.asdf/shims/node

$ type -a yarn
yarn is /home/<user>/.asdf/shims/yarn
yarn is /mnt/c/Program Files (x86)/Yarn/bin/yarn
Enter fullscreen mode Exit fullscreen mode
  • Check which ruby and gems your directory is referring to (in case you have more than 1 ruby version installed)
$ which ruby
/home/<user>/.asdf/shims/ruby

$ which gem
/home/<user>/.asdf/shims/gem
Enter fullscreen mode Exit fullscreen mode
  • If not in .asdf/shims, do asdf reshim ruby 3.0.2 (specify the version yourself, mine here is 3.0.2)
  • Install gems
$ gem install rails
Enter fullscreen mode Exit fullscreen mode

References

  1. Microsoft WSL2 Documentation
  2. asdf virtual manager Documentation
  3. WSL 2: Getting started
  4. BUILD FAILED (Ubuntu 20.04 using ruby-build 20210804)
  5. Installing asdf and using it to install Go, Python & Terraform
  6. Installing Ruby on Rails Using asdf

Top comments (2)

Collapse
 
nadsmoo profile image
Nadeem

Very good article thank you

Collapse
 
michellelwt profile image
Michelle Loh

Welcome