Well I was facing the same problem, I had ruby & rails installed but I couldn't run them on ZSH

The answer is so simple Just Add the following lines to .zshrc

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Then run

source ~/.zshrc

After that to check if ruby & rails are found by ZSH run

ruby --version
rails --verison
Answer from Escapola on Stack Overflow
Top answer
1 of 2
3

Well I was facing the same problem, I had ruby & rails installed but I couldn't run them on ZSH

The answer is so simple Just Add the following lines to .zshrc

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Then run

source ~/.zshrc

After that to check if ruby & rails are found by ZSH run

ruby --version
rails --verison
2 of 2
1
$~  test.rb
/usr/bin/test.rb: line 2: puts: command not found

This is probably because your script is missing an essential line, often called a "pound-bang line" or, more simply, a "bang line", which tells the operating system what program to use to execute the rest of the file. Typically, for Ruby scripts, it looks like:

#!/usr/bin/ruby

or

#!/usr/bin/env ruby

and MUST be the first line in the file. When the OS opens the file, it looks for #! and, if it sees those, launches the executable at the path given, and passes the script to it. That's basic script execution on a *nix system, and applies to sh/Bash/Perl/Python/Ruby and any number of other executable applications on a *nix system.

ruby test.rb
ruby: No such file or directory -- test.rb (LoadError)

I suspect the second failed because you weren't in the /usr/bin/ directory when you executed that command. Ruby tried to run the script but couldn't find it in the local/current directory.

I'm not trying to be cruel, but, as a programmer, you'll spend a huge amount of time at the command-line, especially so if you are programming in C/C++, Perl, Ruby, Python, or any non-IDE based language. You have to learn how the OS works otherwise disasters of varying sizes and shapes await you, so, in parallel to learning a language you need to learn how to use, and administer, your OS. You don't have to be a power-user or administrator, but you have to know enough to understand good instructions from ones that don't apply, or are just plain-wrong.

🌐
Medium
bgsnorfa.medium.com › fix-rbenv-or-ruby-command-not-found-after-changing-from-bash-to-zsh-6ab159e65765
Fix rbenv or ruby command not found after changing from bash to zsh | by Norfa Bagas | Medium
May 21, 2021 - After changing my existing shell console to zsh, I cannot run rbenv or ruby commands. But I already installed both of them. This happens because I have not yet exported rbenv path to zshrc.
Discussions

shell - "zsh: command not found:" when running Ruby commands - Stack Overflow
I still have core commands like ls or pwd working but certain commands relating to Ruby aren't recognised. Not sure if this would apply to other languages but I don't seem to be having any issues w... More on stackoverflow.com
🌐 stackoverflow.com
Bash and ZSH can't find my rubygems. I have been struggling with this for over 12 hours. Help me or kill me.
I don't develop on osx, but given what little I do know and the 12 hours you've spent, at this point it might be worth scrapping your current development environment and creating a new one from scratch. The only guess I might offer with regards to your dotfiles being a breaking change: are you using rvm or another ruby version manager? Or were you managing your ruby version through homebrew / other means? More on reddit.com
🌐 r/rails
11
2
March 10, 2017
Rails no longer working after installing oh-my-zsh
I recently configured oh-my-zsh, but I am now unable to access Rails in my command line (both zsh and bash are throwing me an error saying I do not have rails installed and I need to install). I ha... More on github.com
🌐 github.com
13
July 15, 2017
zsh: command not found: colorls
Description After running gem install colorls I get this message: ******************************************************************* Changes introduced in colorls Sort by dirs : -sd flag has been ... More on github.com
🌐 github.com
22
February 28, 2019
🌐
Moncef Belyamani
moncefbelyamani.com › troubleshooting-command-not-found-in-the-terminal
How to fix "command not found" after installing gems
March 17, 2023 - However, note that I don’t recommend installing Ruby with Homebrew because sooner or later you’ll regret it. Another reason why commands might not be found, or why the newer version of a tool is not being used, even though you updated the PATH in your shell startup file, is because those changes don’t take effect right away. You have to “refresh” it by either using the source command, such as: source ~/.zshrc ·
🌐
Stack Overflow
stackoverflow.com › questions › 64785461 › zsh-command-not-found-when-running-ruby-commands
shell - "zsh: command not found:" when running Ruby commands - Stack Overflow
Backticks run a command in your ... PATH, then you're going to have issues. Either update your PATH before running your application, or add it in your Ruby script like so:...
🌐
Reddit
reddit.com › r/rails › bash and zsh can't find my rubygems. i have been struggling with this for over 12 hours. help me or kill me.
r/rails on Reddit: Bash and ZSH can't find my rubygems. I have been struggling with this for over 12 hours. Help me or kill me.
March 10, 2017 -

Yesterday, because I'm an idiot, I deleted the content of my ~/.zshrc and ~/.bashrc files. Now, I can't start my rails server, console, anything - it says it cant find my gems. PLEASE answer a few questions:

  1. Why do I even have both ZSH and Bash? Did homebrew install one?

  2. Why does my terminal (iTerm) seem to switch between zsh and bash depending on what program I'm running?

  3. Should I delete bash or zsh and focus on fixing the path to my gems?

  4. How do I FIND the path to my gems? I have tried 'gem environment' and pasting the output from there (4 lines? 4 environments?) but it doesnt seem to work. I just want my system to work how it did 2 days ago :(

  5. How could this have happened to me? Are most devs no stupid enough to delete these files? Im shocked this simple thing has had such devastating consequences. This must be why devs back up their dotfiles on github?

  6. Should I focus on installing rails, gems, etc where it IS looking? I keep getting 'cant build for this or that reason' so thats a nonstarted as well.

This whole situation is like, every thread I pull on, something else falls apart. Please help.

🌐
GitHub
github.com › ohmyzsh › ohmyzsh › issues › 6190
Rails no longer working after installing oh-my-zsh · Issue #6190 · ohmyzsh/ohmyzsh
July 15, 2017 - Rails is not currently installed on this system. To get the latest version, simply type: $ sudo gem install rails You can then rerun your "rails" command. When I do as instructed and run sudo gem install rails: Error installing rails: activesupport requires Ruby version >= 2.2.2.
Author   d00medman
🌐
GitHub
github.com › athityakumar › colorls › issues › 264
zsh: command not found: colorls · Issue #264 · athityakumar/colorls
February 28, 2019 - zsh: command not found: colorls · which ruby: /usr/local/opt/ruby/bin/ruby ruby --version: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18] Relevant Issues : (none) Relevant PRs : (none) Type of issue : [ X] Installation · Font-related · Feature request ·
Author   dylanjm
Find elsewhere
🌐
Ruby on Rails
discuss.rubyonrails.org › rubyonrails-talk
why ???zsh: command not found: rails - rubyonrails-talk - Ruby on Rails Discussions
March 26, 2012 - $gem install rails -n /home/steven/.rvm/gems/ruby-1.9.2-p318/bin -l Successfully installed rails-3.2.2 1 gem installed Installing ri documentation for rails-3.2.2... Installing RDoc documentation for rails-3.2.2... $rvm use 1.9.2 $ rails -v zsh: command not found: rails
🌐
Jekyll Talk
talk.jekyllrb.com › t › installation-probelm-zsh-command-not-found-jekyll › 4116
Installation probelm: zsh: command not found: jekyll - Jekyll Talk
March 23, 2020 - I am having difficulty installing Jekyll. The gem gets is installed but when I issue jekyll serve i get zsh: command not found: jekyll Would really appreciate it if somebody could help me out?
🌐
GitHub
github.com › jeremyramin › terminal-plus › issues › 8
zsh: command not found · Issue #8 · jeremyramin/terminal-plus
September 16, 2015 - I'm trying to use this terminal in a Rails project and when I run any command like: bundle exec rails server bundle install I get somethin like: zsh: command not found: bundle If I run rails server without bundler I get /usr/bin/env: rub...
Author   siklodi-mariusz
🌐
Salayhin
salayhin.wordpress.com › 2016 › 08 › 01 › zsh-command-not-found-bundle-error
zsh: command not found: bundle error | Salayhin
January 17, 2017 - I have installed zsh in my ubuntu 16.04, but after install rails when trying to bundle install I found following error in my console: zsh: command not found: bundle (after gem install bundle) After searching on google I found following solution from stackoverflow.com: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv echo 'eval "$(rbenv init -)"' >> ~/.zshenv…
🌐
RVM
rvm.io › integration › zsh
RVM: Ruby Version Manager - ZSH Integration with RVM.
If you're using zsh (possibly with oh-my-zsh) and your prompt displays the current directory as "~rvm_rvmrc_cwd", the fix to add the following to your shell file before sourcing rvm: