asdf-ruby icon indicating copy to clipboard operation
asdf-ruby copied to clipboard

Switching back to ruby 2.6 after installing / using 2.7 - strange ruby errors

Open joemsak opened this issue 5 years ago • 13 comments

When I try to switch back to asdf local ruby 2.6.5 after having been in 2.7.0 ruby no longer works. I've tried removing / re-adding the ruby plugin, I've tried updating asdf, and I've tried reinstalling 2.6.5, and nothing works, giving me a strange error I can't get any google results about

% asdf exec ruby -v
Traceback (most recent call last):
/Users/joemsak/.asdf/installs/ruby/2.6.5/bin/ruby: invalid option -:  (-h will show valid options) (RuntimeError)
% asdf install ruby 2.6.5
Downloading ruby-build...
Cloning into '/Users/joemsak/.asdf/plugins/ruby/ruby-build-source'...
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 10245 (delta 0), reused 0 (delta 0), pack-reused 10244
Receiving objects: 100% (10245/10245), 2.16 MiB | 300.00 KiB/s, done.
Resolving deltas: 100% (6667/6667), done.
Note: switching to 'v20191225'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at c937a09 ruby-build 20191225
Downloading openssl-1.1.1d.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2
Installing openssl-1.1.1d...
Installed openssl-1.1.1d to /Users/joemsak/.asdf/installs/ruby/2.6.5

Downloading ruby-2.6.5.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.5.tar.bz2
Installing ruby-2.6.5...
ruby-build: using readline from homebrew
Installed ruby-2.6.5 to /Users/joemsak/.asdf/installs/ruby/2.6.5


Running: gem install bundler: --version 1.17.3 ... FAIL: /Users/joemsak/.asdf/installs/ruby/2.6.5/bin/ruby: invalid option -:  (-h will show valid options) (RuntimeError)
kadenzeweb upgrade-rails % asdf reshim ruby
kadenzeweb upgrade-rails % ruby -v
Traceback (most recent call last):
/Users/joemsak/.asdf/installs/ruby/2.6.5/bin/ruby: invalid option -:  (-h will show valid options) (RuntimeError)

(my .gemrc locks bundler to 1.17.3, for rails 4.2)

I have no idea what to do, the last time I got stuck like this was a week or so ago and I reinstalled my entire OS as a result (macOS Catalina)

Thanks for your time!

joemsak avatar Jan 11 '20 20:01 joemsak

You are not alone. I have re-installed and uninstalled both rbenv and rvm in attempt to fix this issue without success. Getting the weird behavior below when using ruby 2.6.5 with ruby 2.7.0 installed:

(base) ➜  ~ rvm list
 * ruby-2.6.5 [ x86_64 ]
=> ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ rvm use 2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ bundle -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ gem -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)

nahuakang avatar Jan 22 '20 00:01 nahuakang

any update on this ?

t0nylombardi avatar Jan 31 '20 04:01 t0nylombardi

I'm having the same issue. I can no longer access my older ruby projects.

coros-sanborn avatar Feb 05 '20 00:02 coros-sanborn

Funny, I have the same problem but with rvm.

Edit:

unset RUBYOPT

solved for me, but my problem was with rvm.

rafaelcgs10 avatar Feb 05 '20 15:02 rafaelcgs10

Thank you @rafaelcgs10. I am also using rvm to install and manage different versions of ruby and I was also facing the above problem with ruby 2.7.0. I had set to export RUBYOPT='-W:no-deprecated -W:no-experimental' in bashrc to disables warnings from ruby as it was throwing lots of warnings when used with latest Rails 6 and commenting the RUBYOPT from bashrc solved the problem.

Weird thing with this is that, it happened with me twice and both the times it did not happen immediately after setting the RUBYOPT in bashrc but the problem starts appearing after the next restart of the system.

Can you guys help regarding what would be the right place to report this bug? should it be reported in rvm or ruby?

bhaskarshankarling avatar Feb 16 '20 09:02 bhaskarshankarling

Same issue with rbenv having 2.7.0 installed and then trying to use 2.6.5.

Running unset RUBYOPT worked for me.

danielsellergren avatar Mar 21 '20 16:03 danielsellergren

Having the same problem here, any solution?

haroldofurtado avatar Apr 15 '20 13:04 haroldofurtado

unset RUBYOPT

datty258 avatar Apr 20 '20 03:04 datty258

Funny, I have the same problem but with rvm.

Edit:

unset RUBYOPT

solved for me, but my problem was with rvm.

rbenv 1.1.2, ruby 2.6.6, 2.6.4, 2.6.0 (client projects with specific needs) working after unset RUBYOPT

ramonrails avatar May 07 '20 12:05 ramonrails

Solution: https://github.com/asdf-vm/asdf-ruby/issues/154#issuecomment-582469166

Ah damn! I wish this had been the first result in Google? I ended up here by guessing after hours of trying to debug this issue! Sure enough, there was a RUBYOPT value set in zshrc on this old laptop. 🤦

I feel like ruby really could have helped me out here by mentioning that I had RUBYOPT set to "bleh" 😁

Ok, let's see if we can help some others:

bin/ruby: invalid option -a (-h will show valid options) (RuntimeError) bin/ruby: invalid option -b (-h will show valid options) (RuntimeError) bin/ruby: invalid option -c (-h will show valid options) (RuntimeError) bin/ruby: invalid option -d (-h will show valid options) (RuntimeError) bin/ruby: invalid option -e (-h will show valid options) (RuntimeError) bin/ruby: invalid option -f (-h will show valid options) (RuntimeError) bin/ruby: invalid option -g (-h will show valid options) (RuntimeError) bin/ruby: invalid option -h (-h will show valid options) (RuntimeError) bin/ruby: invalid option -i (-h will show valid options) (RuntimeError) bin/ruby: invalid option -j (-h will show valid options) (RuntimeError) bin/ruby: invalid option -k (-h will show valid options) (RuntimeError) bin/ruby: invalid option -l (-h will show valid options) (RuntimeError) bin/ruby: invalid option -m (-h will show valid options) (RuntimeError) bin/ruby: invalid option -n (-h will show valid options) (RuntimeError) bin/ruby: invalid option -o (-h will show valid options) (RuntimeError) bin/ruby: invalid option -p (-h will show valid options) (RuntimeError) bin/ruby: invalid option -q (-h will show valid options) (RuntimeError) bin/ruby: invalid option -r (-h will show valid options) (RuntimeError) bin/ruby: invalid option -s (-h will show valid options) (RuntimeError) bin/ruby: invalid option -t (-h will show valid options) (RuntimeError) bin/ruby: invalid option -u (-h will show valid options) (RuntimeError) bin/ruby: invalid option -v (-h will show valid options) (RuntimeError) bin/ruby: invalid option -w (-h will show valid options) (RuntimeError) bin/ruby: invalid option -x (-h will show valid options) (RuntimeError) bin/ruby: invalid option -y (-h will show valid options) (RuntimeError) bin/ruby: invalid option -z (-h will show valid options) (RuntimeError) bin/ruby: invalid option -0 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -1 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -2 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -3 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -4 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -5 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -6 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -7 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -8 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -9 (-h will show valid options) (RuntimeError) bin/ruby: invalid option -A (-h will show valid options) (RuntimeError) bin/ruby: invalid option -B (-h will show valid options) (RuntimeError) bin/ruby: invalid option -C (-h will show valid options) (RuntimeError) bin/ruby: invalid option -D (-h will show valid options) (RuntimeError) bin/ruby: invalid option -E (-h will show valid options) (RuntimeError) bin/ruby: invalid option -F (-h will show valid options) (RuntimeError) bin/ruby: invalid option -G (-h will show valid options) (RuntimeError) bin/ruby: invalid option -H (-h will show valid options) (RuntimeError) bin/ruby: invalid option -I (-h will show valid options) (RuntimeError) bin/ruby: invalid option -J (-h will show valid options) (RuntimeError) bin/ruby: invalid option -K (-h will show valid options) (RuntimeError) bin/ruby: invalid option -L (-h will show valid options) (RuntimeError) bin/ruby: invalid option -M (-h will show valid options) (RuntimeError) bin/ruby: invalid option -N (-h will show valid options) (RuntimeError) bin/ruby: invalid option -O (-h will show valid options) (RuntimeError) bin/ruby: invalid option -P (-h will show valid options) (RuntimeError) bin/ruby: invalid option -Q (-h will show valid options) (RuntimeError) bin/ruby: invalid option -R (-h will show valid options) (RuntimeError) bin/ruby: invalid option -S (-h will show valid options) (RuntimeError) bin/ruby: invalid option -T (-h will show valid options) (RuntimeError) bin/ruby: invalid option -U (-h will show valid options) (RuntimeError) bin/ruby: invalid option -V (-h will show valid options) (RuntimeError) bin/ruby: invalid option -W (-h will show valid options) (RuntimeError) bin/ruby: invalid option -X (-h will show valid options) (RuntimeError) bin/ruby: invalid option -Y (-h will show valid options) (RuntimeError) bin/ruby: invalid option -Z (-h will show valid options) (RuntimeError) bundle exec rails webpacker:install

gerrywastaken avatar Aug 15 '20 14:08 gerrywastaken

Funny, I have the same problem but with rvm.

Edit:

unset RUBYOPT

solved for me, but my problem was with rvm.

The solution fixed my issue also(with rbenv)

hiendinhngoc avatar Apr 05 '21 03:04 hiendinhngoc

Is there anything in asdf-ruby contributing to this problem? We use ruby-build for Ruby builds and don't set RUBYOPT anywhere in the code.

Stratus3D avatar Aug 30 '21 19:08 Stratus3D

fwiw; even after removing the RUBYOPT export from zshrc, it still (somehow) persists without a full reboot of the system. i.e. env|grep RUBYOPT still has it even after removing from zshrc and starting a brand new shell/terminal (this is with asdf-vm on Arch Linux)

tl;dr -- if this is still happening even after removing RUBYOPT from your shell config, make sure to reboot.

jonaustin avatar May 30 '22 15:05 jonaustin