Ruby error when trying to launch local host

I am making my way through the Rails for Beginners course and after a bit of a hiatus I started back in it. However, now when I run ruby s I get the following error: ruby: No such file or directory -- s (LoadError) If I run ruby -v I get ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-darwin21] What should I do to get ruby s back up and running?

  1. Make sure run rails s in your Rails project root directory
  2. Try using ./bin/rails s it may works
1 Like

Thank you @Zheng_Cheng I am in the root directory so I tried #2, which returned this error:

/Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require': dlopen(/Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg_ext.bundle, 0x0009): Library not loaded: /usr/local/opt/postgresql/lib/libpq.5.dylib (LoadError)
  Referenced from: /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg_ext.bundle
  Reason: tried: '/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file) - /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg_ext.bundle
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg.rb:49:in `block in <module:PG>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg.rb:37:in `block in <module:PG>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg.rb:42:in `<module:PG>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/pg-1.3.4/lib/pg.rb:6:in `<main>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler/runtime.rb:60:in `block (2 levels) in require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler/runtime.rb:55:in `each'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler/runtime.rb:55:in `block in require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler/runtime.rb:44:in `each'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler/runtime.rb:44:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/3.0.0/bundler.rb:175:in `require'
	from /Users/isaactait/Desktop/Web_Dev/rubyOnRailsApp/config/application.rb:7:in `<main>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/server/server_command.rb:137:in `block in perform'
	from <internal:kernel>:90:in `tap'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/server/server_command.rb:134:in `perform'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.2.3/lib/rails/command/base.rb:87:in `perform'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:48:in `invoke'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from /Users/isaactait/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	from ./bin/rails:4:in `<main>'

Could it be that there something wrong with my postgres setup? If so what can I do to fix it?

FYI - I recently installed the Postgresl app and then this problem cropped up so I uninstalled the app following their docs

Seeing as you’re on MacOS, it’s likely that you could have installed Postgres via HomeBrew. A compatible version of libpq that it’s looking for might be installed, but just could not be located because it’s not properly linked. You could try:

brew link libpq --force

and if that doesn’t work then this might bring things into alignment:

brew update && brew upgrade
1 Like

Thank you @Lorin_Thwaits I ran brew link libpq --force and it returned:

Linking /usr/local/Cellar/libpq/14.4...
Error: Could not symlink bin/clusterdb
Target /usr/local/bin/clusterdb
is a symlink belonging to postgresql. You can unlink it:
  brew unlink postgresql

To force the link and overwrite all conflicting files:
  brew link --overwrite libpq

To list all files that would be deleted:
  brew link --overwrite --dry-run libpq

So, I tried brew link --overwrite libpq and it returned:

Warning: libpq is keg-only and must be linked with `--force`.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

Looks like a catch-22 to me… So, I moved on to brew update && brew upgrade and it returned Already up to date

Next I tried echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc but then ruby s is still returning ruby: No such file or directory -- s (LoadError)

I moved on to brew unlink postgresql then brew link libpq --force and I got

Linking /usr/local/Cellar/libpq/14.4... 377 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

But when I run ruby s I still get the same error…