ruby: invalid option -: (-h will show valid options) (RuntimeError)

kinopyo avatar

kinopyo

This is a funny one.

In How to fix Ruby 2.7 warning: Using the last argument as keyword parameters is deprecated, I shared how to suppress the new warnings for Ruby 2.7, and one of the methods is to set export RUBYOPT='-W:no-deprecated' in your zsh/bash profile.

Turns out, that RUBYOPT='-W:no-deprecated' is only available for Ruby 2.7, so if you're also running rubies that are < 2.7 with rbenv or rvm, you will run into this error.

$ cd older-ruby-projects
$ cat .ruby-version
2.5.7
$ ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)

The solution is, as you might have guessed, simply removing the export RUBYOPT=... setting from the zshrc. ๐Ÿคจ And if you're still bothered by Ruby 2.7 last argument warnings, probably commiting the Warning[:deprecated] = false to your codebase is also a valid option for now.

This wasn't an easy Google search for me, sharing it in case you've also bumped into it.

References:

kinopyo avatar
Written By

kinopyo

Indoor enthusiast, web developer, and former hardcore RTS gamer. #parenting
Published in Ruby
Enjoyed the post?

Clap to support the author, help others find it, and make your opinion count.