user15395591
user15395591

Reputation: 273

Asdf wont switch local version based on tool-versions or using the local command

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

Upvotes: 26

Views: 49109

Answers (16)

boobear
boobear

Reputation: 1

For those who using version 0.16.0, asdf local and asdf global has been replaced by asdf set, breaking change

Upvotes: 0

Brian Santanaa
Brian Santanaa

Reputation: 67

That worked for me(after trying everything I found here and on git):

asdf uninstall ruby <version>
asdf instal ruby <version>

Upvotes: 0

Leandro Arruda
Leandro Arruda

Reputation: 506

As I said in a comment at @roman answer, is the exactly reason that give me error when use local version installed with asdf. The comment of @viacheslav draw my attention to configuration post installation with some shell.

The very old installation config has a "\." (backslash plus dot) to load asdf command line, it is works for a long time but for now I had to remove the backslash. When install from git + bash or brew, like the original answer, it is needed to revisit the configuration.

I update the asdf version but not revisited shell config file (.zshrc in my case).

Correct way to load asdf: enter image description here

Wrong way that worked someday: enter image description here

Upvotes: 0

Seralto
Seralto

Reputation: 1076

Try:

rm ~/.asdf/shims/rails
asdf reshim

Upvotes: 0

Raffy Bandrang
Raffy Bandrang

Reputation: 1

Once Homebrew is installed, you can use it to install Ruby.

brew install ruby This will install the latest Ruby version on Homebrew (which is 2.5.0 at the time of this writing) on /usr/local/bin/ruby. Add /usr/local/bin to the start of your PATH so it becomes the default Ruby.

Add this to ~/.profile or ~/.bash_profile.

export PATH='/usr/local/bin:/usr/local/sbin:$PATH'

If you’re using Ruby to run a few scripts then using the Homebrew version is enough

Upvotes: -1

abax
abax

Reputation: 787

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

asdf plugin-update ruby
asdf install ruby 3.1.4
bundle

Upvotes: 3

Seeni
Seeni

Reputation: 1616

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

Upvotes: 0

Rich Steinmetz
Rich Steinmetz

Reputation: 1301

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

Upvotes: 21

Drew Cordano
Drew Cordano

Reputation: 1120

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

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

And resource

source ~/.zshrc

Upvotes: 5

Roman
Roman

Reputation: 301

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

Upvotes: 20

yosefbennywidyo
yosefbennywidyo

Reputation: 193

You should install bundle gem first

gem install bundle

then you can run bundle or bundle install

Upvotes: 3

Lahiru Jayaratne
Lahiru Jayaratne

Reputation: 1762

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.

Upvotes: 8

otherguy
otherguy

Reputation: 995

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

Upvotes: 12

codesnik
codesnik

Reputation: 319

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.

Upvotes: 0

OBCENEIKON
OBCENEIKON

Reputation: 397

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

Upvotes: 22

NaguiHW
NaguiHW

Reputation: 149

I had a similar issue and I just reinstalled rails.

gem install rails

Upvotes: 0

Related Questions