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"
Share:
7,309

Related videos on Youtube

golymer
Author by

golymer

Updated on September 18, 2022

Comments

  • golymer
    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
      ubfan1 over 8 years
      Do 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.
      A.B. over 8 years
      edit your question and add the output of whoami; echo $PATH
    • AliReza Mosajjal
      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.
    A.B. over 8 years
    Any why? Any explanations please? :)
  • Noki
    Noki over 8 years
    What'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
    golymer over 8 years
    I tried it and now I get a redirection forbidden error whenever I run my code.
  • Noki
    Noki over 8 years
    You 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
    Noki over 8 years
    Trying to help gets you down voted, awesome!