rbenv: ruby: command not found

32,723

Solution 1

  1. The complaint you get comes from rbenv. The fact that it's complaining shows that rbenv is set up and working.

  2. Figure out what version of Ruby is needed to run the project. Either the project comes with a .ruby-version file in the root, or someone on the project will know and recommend that version to use.

  3. If the version is not specified in a .ruby-version file, create the .ruby-version file in the project directory.

  4. type ruby -v while in that directory. Is it OK? Then you have the version of Ruby installed that matches what your .ruby-version is asking for.

  5. If the last command was not OK, then type rbenv install.

Now that Ruby is installed, you need to run your program. I'm assuming it comes with a Rakefile.

  1. install the bundler tool: gem install bundler.

  2. install the dependancies of the project: bundle install

  3. run your project using the exact versions of libraries it specifies: bundle exec rails server

Solution 2

Try the following piece of code depending on the current version of rails that you have installed. In my case am using v2.3.3

rbenv global 2.3.3

Solution 3

Even setting global or local doesn't work if you haven't set this

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
exec $SHELL

Solution 4

Even there is correct answer above, but it is not clear for my first check, so give a complete answer as a summarize based on z5h and Thengugi's answer. After setup and install ruby using rbenv as below (I installed 2.5.0):

rbenv install 2.5.0

You also need set it as the default version in your OS (CentOS for me):

rbenv global 2.5.0
Share:
32,723

Related videos on Youtube

Lawrence DeSouza
Author by

Lawrence DeSouza

Updated on July 09, 2022

Comments

  • Lawrence DeSouza
    Lawrence DeSouza almost 2 years

    I am using rbenv with ruby version 1.9.1-p378 on the local dir.

    Command ruby -v gives the following error:

    rbenv: ruby: command not found
    
    The `ruby' command exists in these Ruby versions:
    2.0.0-p353
    

    Any clue why this happens? The bundle, rails commands do not work either.

    Command rbenv versions :

    * 1.9.1-p378 (set by /home/user/Desktop/r1/noko1/.ruby-version)
    2.0.0-p353
    
    • Малъ Скрылевъ
      Малъ Скрылевъ over 10 years
      As you can see: the ruby app exists only in ruby 2.0.0 version, not in 1.9.1, just switch ruby to 2.0.0
    • Holger Just
      Holger Just over 10 years
      You really (really) don't want to use Ruby 1.9.1 as it is broken in multiple regards (encoding, rubygems, ...) and is generally not supported by anyone. You should use at least Ruby 1.9.2 if you want to use a 1.9 Ruby.
  • Lawrence DeSouza
    Lawrence DeSouza over 10 years
    I thought it was installed, see my edit, when i use rbenv versions
  • Conner
    Conner over 10 years
    Can you share your .rbenv-version file in the desired directory?
  • Lawrence DeSouza
    Lawrence DeSouza over 10 years
    It just has the one line : 1.9.1-p378
  • Lawrence DeSouza
    Lawrence DeSouza over 10 years
    I'm trying to run an application that is giving me problems when i try to run it with 2.0.0. Something about rbconfig/config. That's why I'm trying to use it with 1.9.1. It is also using rails 2.3.2, which I gather from the gemfile of the app. However the rails command also does not work...
  • Conner
    Conner over 10 years
  • Mark Bolusmjak
    Mark Bolusmjak over 10 years
    I have made step by step instructions. Let me know how it goes.
  • Lawrence DeSouza
    Lawrence DeSouza over 10 years
    Yes! Thanks, [rbenv install] to get rubygems working - and then [gem install bundler] were big helps. However I had about 4 or 5 other things to fix including adding [gem rdoc] to the gemfile and installing a few other required gems like sqlite, etc, and finally downgrading the rubygems version again in order to use ./script/server start for rails 2.3.2 ; but after all that it WORKS! Thanks a bundle
  • justinpage
    justinpage over 9 years
    For those still running into this issue, try and close your terminal first and trying again. Worked for me.
  • joe
    joe over 7 years
    As someone who is completely unfamiliar with Ruby, this is the only thing that has worked for me,
  • randmin
    randmin over 3 years
    I had to do this to tell rbenv what version of ruby to use. Insert whatever version you installed using rbenv install x.y[.z] (in my case 2.7.0). Now ruby -v works as expected