Rails installation error

When I install Rails using this command gem install rails I have an error


then I installed the ruby version like the error said but still give me the same error with another version

What operating system are you using and how are you installing Ruby?

I used sudo apt install ruby to install it on Ubuntu

So what is the version you have installed? The error is telling you your Ruby version is too low

The solution is using this command " gem update --system" then “gem install rails”

Unfortunately, after it’s installed I can’t use it.


after looking for version:

Well, what you’ve done is update all gems (ruby packages) on the system to their latest versions. It won’t update the version of Ruby itself. So you’ve updated everything to newest, and you now have gems that try to run, but they can’t find an executable because it doesn’t exist. What they’re looking for (I assume) is a newer version of Ruby, which afaics you don’t have: you’ve just pulled down the default one on apt, which (again, I assume) is an older version with LTS. What is the version of Ruby?

If you have created a Rails app, the gem will be in the app’s Gemfile.lock; not the generic Rails ones

Yes, but if OP starts adjusting the versions of gems in the app’s gemfile, OP will normally find that the rails installation will still break: when they install rails, it requires a specific set of gems with specific versions to work. If OP starts changing those, OP will generally just end up with a broken rails installation unless they are extremely lucky.

@HaithamCa sorry, it’s been a while since I used Ruby, and I should have read the documentation. Also I assume the version is 2.7 from the screenshot, I missed that.

So gem update --system updates RubyGems, as in the program that lets you type gem .....dosomestuff and it goes and gets gems or whatever. That’s it. But RubyGems already comes built into every version of Ruby since 1.9, so there shouldn’t have been any reason to need to do that.

So it hasn’t updated all your gems, that’s just gem update

But what you do have is a version mismatch of something. I would have strongly suggested using a Ruby version manager (rbenv is the main one, asdf is really good), but I think it’s a bit late for that as something has gotten messed up in-between trying to install Rails on a Ruby version that was too low, then updating Ruby, then attempting reinstall. I also wonder whether updating RubyGems itself may have installed a version that may have issues with your version of Ruby, but I don’t think that’s super likely

What is the exact set of commands you have made to get to this point?

1 Like

I found the solution, first if you have different versions of Ruby you have to know which Ruby you use inside the file you are working with. For example, in my case I installed Ruby 3.0.0 globally and Rails 6.3.0 . but first when I cloned a repo it was using Ruby 2.7.0 however I couldn’t Install Rails . So I had to install Ruby 2.7.0 . Then I faced anther problem in gemsfile; mimemagic gets deprecated so I can’t change it by using gem update --system. so I got my hand dirty and changed it manually from gemsfile.lock. Then I got another error “pg” gem then I uninstalled this gem and installed postgresql and installed “pg” again then “bundle install”. Finally I can install Rails.

1 Like

Ah, I didn’t know you were trying to run an existing project. For future reference, do use a ruby version version manager, then you can just switch versions for each project that needs it without having to touch the system version