1

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
golymer
  • 11
  • 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. – ubfan1 Aug 17 '15 at 01:31
  • [edit] your question and add the output of whoami; echo $PATH – A.B. Aug 17 '15 at 06:32
  • @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

    – AliReza Mosajjal Aug 17 '15 at 06:38

2 Answers2

1

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"
0

Try reinstalling ruby maybe?

sudo apt-get install --reinstall ruby

Noki
  • 932
  • Any why? Any explanations please? :) – A.B. Aug 17 '15 at 06:32
  • 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?' – Noki Aug 17 '15 at 08:12
  • I tried it and now I get a redirection forbidden error whenever I run my code. – golymer Aug 17 '15 at 16:32
  • 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: http://askubuntu.com/questions/27213/what-is-the-equivalent-to-the-windows-program-files-folder-where-do-things-g – Noki Aug 17 '15 at 18:47
  • Trying to help gets you down voted, awesome! – Noki Aug 18 '15 at 14:10