bin/bash: ruby command not found. Ruby not in sudo path
7,309
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.rb
notice the text "ruby"
Related videos on Youtube
Author by
golymer
Updated on September 18, 2022Comments
-
golymer over 1 year
I can't seem to run any code on ruby with any text editor. This error is returned when code is run
/bin/bash: ruby: command not found [Finished in 0.0s with exit code 127] [shell_cmd: ruby "/home/user/Resume/ruby/WebScraper/redditscrape.rb"] [dir: /home/user/Resume/ruby/WebScraper] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/user/.rvm/bin]
I found a similar question on stackoverflow sudo: ruby: command not found after ssh
As user terdon explains it's caused by ruby not being in the sudo path. So I tried sudo-ing my
type ruby
but nothing happened. How do I fix this? Thanks in advance!if this helps my
type ruby
is/home/user/.rvm/rubies/ruby-2.2.2/bin/ruby
and my echo path is
/home/user/.rvm/gems/ruby-2.2.2/bin:/home/user/.rvm/gems/ruby-2.2.2@global/bin:/home/user/.rvm/rubies/ruby-2.2.2/bin:/home/user/.rvm/bin:/usr/local/heroku/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
-
ubfan1 over 8 yearsDo you need the 2.2.2 version? The ruby package on my 14.04 system is at 1.9.1, and puts ruby in /usr/bin.
-
A.B. over 8 yearsedit your question and add the output of
whoami; echo $PATH
-
AliReza Mosajjal over 8 years@ubfan1your $PATH shows
/bin/ruby
is not in there. try adding it by issuing this command:export PATH=$PATH:$HOME/user/.rvm/rubies/ruby-2.2.2/bin/ruby
-
-
A.B. over 8 yearsAny why? Any explanations please? :)
-
Noki over 8 yearsWhat's broken is something usually configured during installation. Perhaps a reinstallation will fix it. It's next in line to 'Have you tired turning it off and on again?'
-
golymer over 8 yearsI tried it and now I get a redirection forbidden error whenever I run my code.
-
Noki over 8 yearsYou clearly have something wrong with the system. That is a simple remove and install command which had 0 impact on my system when I ran it just now. I suggest looking at your /bin/ folder, then /usr/bin/ to see if the Ruby app is actually present in the first place. There seems to be some useful info on how this is structured here: askubuntu.com/questions/27213/…
-
Noki over 8 yearsTrying to help gets you down voted, awesome!