ruby-build: Cannot load such file -- optparse (LoadError)

Hi guys, anyone encountered this issue while installing 2.7.1?

$ rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...

BUILD FAILED (Pop 20.04 using ruby-build 20200224-73-g0a5e059)

Inspect or clean up the working tree at /tmp/ruby-build.20200821113417.841610.nXIFsy
Results logged to /tmp/ruby-build.20200821113417.841610.log

Last 10 log lines:
        LC_CTYPE =
        MFLAGS =
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

./tool/file2lastrev.rb:6:in `require': cannot load such file -- optparse (LoadError)
        from ./tool/file2lastrev.rb:6:in `<main>'
make: *** [uncommon.mk:1130: revision.tmp] Error 1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (7 by maintainers)

Most upvoted comments

fixed this by uninstall rbenv and reinstall with homebrew for ubuntu

I met same issue on Ubuntu 21.04 amd64.

I used system ruby instead of ruby-build’s ruby 😅

sudo apt install ruby
rbenv global system
rbenv rehash
rbenv install 2.7.4

refs: ruby-buildでRubyをインストールしようとしたらoptparseが無いって言われる - ser1zw’s blog

@mislav Finally I install 3.0.1 success as following step

  1. Install 2.7.3
  2. Set global version to 2.7.3
  3. Install 3.0.1 again, no error.

I’m facing the same issue with 2.7.0 in Void Linux x86_64.

My solution, based on previous comments, was to set RUBY_CONFIGURE_OPTS to indicate the “BASERUBY” (which I don’t know what it means) and then install as usual:

$ rbenv versions
* system
  2.5.7
  2.6.6
$ export RUBY_CONFIGURE_OPTS=" --with-baseruby=$HOME/.rbenv/versions/2.6.6/bin/ruby"
$ rbenv install 2.7.0
Installing ruby-2.7.0...
Installed ruby-2.7.0 to $HOME/.rbenv/versions/2.7.0

From the log, when rbenv install 2.7.0 fails, I can see the next message:

   * BASERUBY -v:         ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) \
                          [x86_64-linux]

---
	BASERUBY = $HOME/.rbenv/shims/ruby --disable=gems

And notice that ruby 2.7.4p191 is system:

$ rbenv shell system
$ ruby --version
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]

Now, reading https://github.com/ruby/ruby/blob/master/configure.ac#L50 makes me wonder if a previous version of Ruby is needed to build Ruby >= 2.7.0?: “executable host ruby is required. use --with-baseruby option”.

Whats your opinion? 🤔

https://github.com/rbenv/ruby-build/issues/1484#issuecomment-814918917 is a strange behavior for me. Because I never faced that with my macOS and linux boxes.

I try to reproduce it.