Ask coding questions

← Back to all posts
How do I add a package to a Ruby repl?
CT3000 (4)

I am unable to get packages installed in a Ruby repl.

Here are the reproduction steps:

  • Click on 'new repl'
  • Choose 'Ruby' for the language
  • Click 'Create Repl'
  • On the left, click on the package icon
  • Add a package. In my example, I added 'bcrypt'
  • Note that the package appears to be installed correctly, and shows up in Gemfile and Gemfile.lock
  • Try to use the gem. Write some code that uses it, click 'run', and fail.

Taking a look at my example repo, you can see I require "bcrypt" and this fails if I run the code. I get "cannot load such file -- bcrypt". If instead, I type bundle exec ruby main.rb, the gem is loaded successfully. However, there seems to be no way to make this workaround 'stick' to the run button.

Answered by SixBeeps (5067) [earned 5 cycles]
View Answer
SixBeeps (5067)

If you can get it to run in console, try making a .replit file