14

I downloaded asdf the other day and am trying to use it with a ruby on rails project I downloaded from Github. When I run asdf install, I get this response:

firebase 9.10.0 is already installed
ruby 2.7.2 is already installed

Then I run rails s :

No preset version installed for command rails
Please install a version by running one of the following:

asdf install ruby 2.7.2

or add one of the following versions in your config file at 
/Users/******/Desktop/****/.tool-versions
ruby 3.0.1

The project runs on ruby 2.7.2.

.tool-versions:

ruby 2.7.2
node 12.18.3

I installed asdf with homebrew and use oh-my-zhs with the asdf plugin.

EDIT: running

asdf install ruby 2.7.2

just says

ruby 2.7.2 is already installed
Flux
  • 9,805
  • 5
  • 46
  • 92
user15395591
  • 153
  • 1
  • 1
  • 7

11 Answers11

10

For people experiencing this issue, who've installed asdf via Homebrew and who are using the standard ZSH shell (no oh-my-zsh plugins), don't forget to source the asdf bash script:

echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc
Roman
  • 101
  • 1
  • 3
9

You need to reshim ruby. Run asdf reshim ruby and then try running rails s again.

OBCENEIKON
  • 167
  • 9
  • So weird, the command line was saying the right version when I checked `asdf current` or did `ruby -v` but this seems to have fixed it thanks! Saved me a big headache. I wonder why they do not do this automatically when installing/changing versions? There must be a reason because it seems too trivial to not just do it. Seems there's some info here: https://github.com/asdf-vm/asdf-ruby/issues/63 – CTS_AE Nov 16 '21 at 17:58
  • Thanks; the reshim command worked for the same issue I was having with kubectl not switching versions with asdf. `adsf reshim kubectl` – BDF Sep 08 '22 at 18:37
  • If this doesn't work, check if you have added `. /opt/homebrew/opt/asdf/libexec/asdf.sh` to ~/.zhrc file. – Seeni Nov 09 '22 at 10:22
8

For RubyMine users

If you run the terminal commands inside of your integrated RubyMine terminal, nothing will change until you change the project SDK to the newly installed version. After restarting your terminal, everything should work as expected.

Here's where you can find the setting, check the box next to the sdk you want to use for the project: enter image description here

patrickbadley
  • 2,510
  • 2
  • 29
  • 30
Rich Steinmetz
  • 1,020
  • 13
  • 28
4

The following steps given by purplespline that I found in this Reddit thread worked for me:

asdf exec gem install rails

then you should be able to run other rails commands.

Lahiru Jayaratne
  • 1,684
  • 4
  • 31
  • 35
2

If Ruby 2.7.2 is already in your .tool-versions file, you can fix this by simply running

$ bundle

This will install the correct version of the Rails gem and everything should work again.

Try looking at the output of shim-versions first and you will most likely see that Ruby 2.7.2 is there, but Rails 2.7.2 is not:

$ asdf shim-versions rails
ruby 2.7.0

$ asdf shim-versions ruby
ruby 2.7.2
ruby 2.7.0
otherguy
  • 709
  • 6
  • 13
2

You should install bundle gem first

gem install bundle

then you can run bundle or bundle install

yosefbennywidyo
  • 163
  • 4
  • 8
2

On my end I did not export or add this on my zshrc

. /opt/homebrew/opt/asdf/libexec/asdf.sh

And resource

source ~/.zshrc
Drew Cordano
  • 962
  • 9
  • 16
0

I had a similar issue and I just reinstalled rails.

gem install rails
NaguiHW
  • 43
  • 6
0

for diagnostics, please check out outputs of

which ruby

and

ruby --version

in the working directory of your project. If it indeed shows you ruby version 2.7.2, then run "gem install rails" or ("bundle install" if gemfile.lock is present) from this working directory again.

One common mistake is not to open new shell after modification of shell config files. Also zsh requires to run "rehash" command if some program is installed at different path, but reopening shell will solve that.

codesnik
  • 299
  • 2
  • 7
0

One more tip: check if you have updated .bashrc or .zshrc as in the installation guide.

Seeni
  • 1,518
  • 1
  • 14
  • 22
0

This is what worked for me. I had forgotten to bundle after updating.

asdf plugin-update ruby
asdf install ruby 3.1.4
bundle
abax
  • 727
  • 5
  • 9