First steps with Rails derailed - problems with starting project

Hi! I would love to start my journey with Ruby on Rails but many of my attempts had failed miserably. Here are few of my problems when going through Getting Started with Rails:

  1. gem install rails failes on every attempt. I tried on two different computers one is MacBook and other is old Lenovo laptop with Fedora onboard. I always get connection error. I have checked in three different locations and Internet providers. I dont use proxy or anything. My error is:
ERROR:  Could not find a valid gem 'rails' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)

Apart from those attempts I have read multiple threads on forums, blogs, etc. Trying solutions with SSL certificate, getting gems through http rather than https and so on. Asked milion questions to chatgpt but nothing helped.

  1. Getting Started with Dev Containers after failing on many attempts with installing rails. I have tried my luck with docker. Using this way of starting new project I got an error:
Step 5/8 : RUN groupadd -g $GROUP_ID app && useradd -u $USER_ID -g app -m app
 ---> Running in 31095dedeb84
groupadd: GID '0' already exists
The command '/bin/sh -c groupadd -g $GROUP_ID app && useradd -u $USER_ID -g app -m app' returned a non-zero code: 4
thread 'main' panicked at src/main.rs:41:5:
assertion failed: status.success()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To combat that error I ve had clone rails-new repository and just changed line 5 in Dockerfile.unix to just “RUN useradd app” and builed the tool. Everything is fine up until this point:

Successfully tagged rails-new-3.3.4-7.2.0:latest
/usr/local/lib/ruby/3.3.0/fileutils.rb:402:in `mkdir': Permission denied @ dir_s_mkdir - /home/jk/Code/rails-new/rails-new (Errno::EACCES)

I have added docker group to user, tried to run rails-new with sudo and as logged in root but every time I got this error. I have heard about great developer experience with Rails but why am I going through such problems just trying to start project? If you gone through such problems or may know where is problem please help me. With regards frontend developer derailed from starting new project.

1 Like

What is your ruby version?

Can you share the full logs?

You can use ruby version manager like:

My version is ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-darwin23] (on Mac)

Yes of course here is gem install rails --debug

jk@MacBook-Pro-Jakub blog % gem install rails --debug
NOTE:  Debugging mode prints all exceptions even when rescued
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1603 - execution expired
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1605 - Failed to open TCP connection to index.rubygems.org:443 (execution expired)
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1691 - Failed to open TCP connection to index.rubygems.org:443 (execution expired)
Exception `Gem::RemoteFetcher::FetchError' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/remote_fetcher.rb:265 - Gem::Net::OpenTimeout: Failed to open TCP connection to index.rubygems.org:443 (execution expired) (https://index.rubygems.org/versions)
Exception `Errno::ENOENT' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/remote_fetcher.rb:288 - No such file or directory @ rb_file_s_stat - /Users/jk/.gem/specs/rubygems.org%443/prerelease_specs.4.8
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1603 - execution expired
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1605 - Failed to open TCP connection to rubygems.org:443 (execution expired)
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1691 - Failed to open TCP connection to rubygems.org:443 (execution expired)
Exception `Gem::RemoteFetcher::FetchError' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/remote_fetcher.rb:265 - Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/prerelease_specs.4.8.gz)
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1603 - execution expired
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1605 - Failed to open TCP connection to rubygems.org:443 (execution expired)
Exception `Gem::Net::OpenTimeout' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/vendor/net-http/lib/net/http.rb:1691 - Failed to open TCP connection to rubygems.org:443 (execution expired)
Exception `Gem::RemoteFetcher::FetchError' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/remote_fetcher.rb:265 - Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)
Exception `Gem::RemoteFetcher::FetchError' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/spec_fetcher.rb:248 - Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)
Exception `Gem::UnsatisfiableDependencyError' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/resolver.rb:228 - Unable to resolve dependency: user requested 'rails (>= 0)'
ERROR:  Could not find a valid gem 'rails' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)
Exception `Errno::ENOENT' at /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/remote_fetcher.rb:288 - No such file or directory @ rb_file_s_stat - /Users/jk/.gem/specs/rubygems.org%443/latest_specs.4.8

Yes, I did use rbenv on last attempt but unfortunately I did not change a thing.

Maybe this Ruby can't connect to rubygems.org · Issue #2342 · rubygems/rubygems · GitHub relates to your problem

This is a step in the right direction. I change ruby version with rbenv to

ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin23]

but when run

jk@MacBook-Pro-Jakub ~ % gem install rails
ERROR:  Could not find a valid gem 'rails' (>= 0) in any repository

It looks like error with TCP connection is no more. When run:

jk@MacBook-Pro-Jakub ~ % gem update --system
Latest version already installed. Done.

Then i checked sources and saw this:

jk@MacBook-Pro-Jakub ~ % gem sources
*** CURRENT SOURCES ***

Absolutely no sources are present so I run this:

jk@MacBook-Pro-Jakub ~ % gem sources --add https://rubygems.org/
Error fetching https://rubygems.org/:
	Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)

Trying to add source without https connection is the same:

jk@MacBook-Pro-Jakub ~ % gem sources --add http://rubygems.org/
https://rubygems.org is recommended for security over http://rubygems.org/

Do you want to add this insecure source? [yn]  y
Error fetching http://rubygems.org/:
	Net::OpenTimeout: Failed to open TCP connection to rubygems.org:80 (execution expired) (http://rubygems.org/specs.4.8.gz)

It looks like my problem is not related to ruby version? I will try this steps on other computer and when I run into something new I will get you posted.

If related to SSL, check this: Bundler: How to troubleshoot RubyGems and Bundler TLS/SSL Issues

Check SSL version: openssl version

With ruby version

ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin23]

and latest ruby version. Openssl version 3.4.0 installed using homebrew. I had double checked with downgraded

OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)

When I run

brew link --overwrite ruby

I had no luck and still got

jk@MacBook-Pro-Jakub ~ % gem sources --add https://rubygems.org/
Error fetching https://rubygems.org/:
	Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)

Finally I have found solution!

This discussion had helped me unable to download from rubygems #2322

On my Mac I just turned off IPv6 like this:

jk@MacBook-Pro-Jakub ~ % sudo networksetup -setv6off "Wi-Fi"

Now gems are downloading as they should. I just download rails and created new blog project:

rails new blog

but when I run:

jk@MacBook-Pro-Jakub blog % bin/rails server
bin/rails:3:in `require_relative': cannot load such file -- /Users/jk/Developer/blog/config/boot (LoadError)
	from bin/rails:3:in `<main>'

Ok, it doesnt look too bad I just add this file boot.rc file with help of chatgpt. My boot.rc file:

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" if File.exist?("Gemfile.lock") # Speed up boot time by caching expensive operations.

but when I run bundle install I see this:

jk@MacBook-Pro-Jakub blog % bundle install
Your Ruby version is 3.3.6, but your Gemfile specified 2.6.10

:confused:

jk@MacBook-Pro-Jakub blog % rails -v
Your Ruby version is 2.6.10, but your Gemfile specified 3.3.6

I should have said that my Gemfile originally had:

ruby '2.6.10'

That I had changed to 3.3.6 that I had installed by homebrew. How to fix this behavior? Does gem is linked to system ruby and not homebrew installed one? I also saw this when tried soulution from stackoverflow that you have send @yosefbennywidyo

jk@MacBook-Pro-Jakub blog % brew link --overwrite ruby
Warning: Refusing to link macOS provided/shadowed software: ruby
If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/jk/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

For pkg-config to find ruby you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
jk@MacBook-Pro-Jakub blog %     

Maybe here is my problem?

  • Install ruby ‘2.6 10’ with rbenv:

rbenv install 2.6.10

Make sure you read suggested build environment

  • Switch your ruby version to ruby ‘2.6.10’:

rbenv local 2.6.10

  • install required gems

bundle

I`m pretty sure that 2.6.10 is my system version of ruby so couldn’t I use it without installing?

I would like to work on latest Rails 8.0.0 as It is recommend in Getting Started with Rails. My system 2.6.10 version of ruby would work up to 6.0.0 version?

Thankfully I just started my first rails project :smile: I managed it with:

rbenv 1.3.0
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-darwin23]
OpenSSL 3.4.0 22 Oct 2024 (Library: OpenSSL 3.4.0 22 Oct 2024)
gem 3.5.23
Rails 8.0.0

Here is quick recap of my last problem. I ve had installed at some point with system ruby. Rails in version 6.0.6.1 or something like that. When I launched rails new blog It used old version of rails and that was the reasone for creating project with old ruby version in Gemfile. So it worked as intendet.

It was enough to remove old rails version run exec $SHELL and rails -v returned with Rails 8.0.0. From there it went smoothly. I created new app, installed dependencies with bundle install and bin/rails server started application in development.

Thank you very much @yosefbennywidyo for helping me find solution for many problems I had faced. It was very helpful to get some feedback and second look.

For anyone having similar problems with gem install check if IPv6 is guilty :slight_smile: Tommorow I will finally start my new adventure in world of Ruby on Rails wish me luck to not derailed anymore :wink:

1 Like

Congrats @jks welcome to Ruby on Rails :rocket:

1 Like