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 OverflowWell 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
$~ 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.
shell - "zsh: command not found:" when running Ruby commands - Stack Overflow
Bash and ZSH can't find my rubygems. I have been struggling with this for over 12 hours. Help me or kill me.
Rails no longer working after installing oh-my-zsh
zsh: command not found: colorls
I had the same issue using zsh and this fixed it:
Copy$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
You seem to be after installing bundler system-wide. To do this, you need to pass --no-user-install flag to gem and execute it with sudo:
Copysudo gem install bundler --no-user-install
After this, you should see bundle in /usr/bin/ just fine:
Copy$ ls /usr/bin/bundle
/usr/bin/bundle*
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:
Why do I even have both ZSH and Bash? Did homebrew install one?
Why does my terminal (iTerm) seem to switch between zsh and bash depending on what program I'm running?
Should I delete bash or zsh and focus on fixing the path to my gems?
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 :(
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?
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.
I have faced the same issue and fumbled to find an answer. here is how I solved it.
- start the program with the following shibang line so that ubuntu knows it is a ruby file.
#!/usr/bin/env ruby - change the directory to where your code lives
cd /home/User1/program - make your file executable by running
chmod +x your_program.rb - type in the terminal
ruby your_program.rbnotice the text "ruby"
Try reinstalling ruby maybe?
sudo apt-get install --reinstall ruby
What went wrong?
During installation, rvm puts two lines (first one is a comment though) in ~/.bash_profile file to help bash recognize ruby binaries. But the problem is Ubuntu's bash ignores this file. As a result, it doesn't know that you already installed ruby and prompts you to install ruby!
The problem can be solved in two different way.
Solution 1: Using ~/.bashrc file
Open your ~/.bashrc file and put these two lines (or last one) there.
### Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Solution 2: Make the regular shell session as login shell
Or you can turn on your virtual terminal's preference to consider the shell as Login Shell. The settings can be found in -
Gnome Terminal: Menu > Edit > Profile Preference > Command Tab > Run command as a login shell
Mate Terminal: Menu > Edit > Profile Preference > Title & Command Tab > Run command as a login shell
Xfce4 Terminal: Menu > Edit > Preference > General Tab > Run command as login shell
Either one will do the job.
Another solution could be installing Ruby in System using Ubuntu's repository. But that defeats the purpose of using rvm at first place.
You can install Ruby by typing:
sudo apt-get install ruby-full
See the Doc.
You could also try adding the following lines to your .zshrc file:
# Load rbenv if installed
export PATH="${HOME}/.rbenv/bin:${PATH}"
type -a rbenv > /dev/null && eval "$(rbenv init -)"
I've found the answer.
I run these and works perfectly.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
echo 'eval "$(rbenv init -)"' >> ~/.zshenv
echo 'source $HOME/.zshenv' >> ~/.zshrc
exec $SHELL
You need to add two things to your PATH.
First rbenv itself and second the ruby shims.
Part 1 rbenv
Installation
Homebrew
If you installed rbenv with brew,
then the rbenv executable should be linked to /usr/local/bin/rbenv.
See homebrew installation documentation for details.
Please add /usr/local/bin to your path PATH, if it is missing.
# in ~/.zshrc
export PATH=/usr/local/bin:$PATH
Github Checkout
If you install rbenv via a Github checkout, then the rbenv executalbe should be stored in ~/.rbenv/bin.
See github installation documentation for details.
Please add ~/.rbenv/bin to your path PATH, if it is missing.
# in ~/.zshrc
export PATH=$HOME/.rbenv/bin:$PATH
Verfiy
Please verify that rbenv is in your path by calling which rbenv.
The installation path should be returend.
Part 2 shims
Add the ruby shims to you path.
# in ~/.zshrc
eval "$(rbenv init -)"
Instead of the eval "$(rbenv init -)" command you can also add the shims folder directly.
# in ~/.zshrc
export RBENV_ROOT=$HOME/.rbenv
export PATH=$RBENV_ROOT/shims:/versions:$PATH
Part 3 rbenv doctor
You might also run the rbenv-doctor script mentioned here,
to check your installation.
I had this same error. I could run which rbenv and rbenv just fine, but no matter what I would get command not found: rbenv. The issue was that I had eval "$(rbenv init -)" in my ~/.zshenv and not my ~/.zshrc file. You may still have the path to rbenv be added to $PATH within ~/.zshenv for it to work.
I had exactly the same problem, and it turned out to be that I hadn't moved an essential line from ~/.bashrc to ~/.zshrc. Putting it in at the end and reopening the terminal fixed the problem:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
For people using rbenv, you should move your rbenv initialization to ~/.zshenv as in http://coderwall.com/p/0o64yq?i=1&p=1&q=author%3Awilhelmbot