ruby cmd not working in folders rbenv: ruby: command not found - ruby

ruby cmd works in the below folder. But when I get into another folder, it wont work.
pwd
/Users/abc/git/lib
ruby --version
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin19]
When I do the same command , I get error
pwd
/Users/abc/git/lib/test
ruby --version
rbenv: ruby: command not found
The `ruby' command exists in these Ruby versions:
2.5.3

It is weired but it could be a different .local file inside the test folder. Run rbenv version in both folder so we can see if there is a local setting for rbenv.

Related

Cannot use RSpec (rspec: command not found)

So I installed the newest version of Ruby:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
By following these steps:
brew install ruby
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
I needed to change the Path so that I could use the newest version of Ruby since if not, whenever I did
ruby -v
It would just take into account the default ruby version I had installed in my MAC:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
Everything works great but I want to install RSpec, so I do:
gem install rspec
This is what I get:
Successfully installed rspec-3.10.0
Parsing documentation for rspec-3.10.0
Done installing documentation for rspec after 0 seconds
1 gem installed
But once I check the version:
rspec --version
This is what I get:
-bash: rspec: command not found
I have uninstalled ruby with brew and installed it again and restarted the terminal but to no avail...Any idea why is this happening? How can I solve it?
Thank you!
It seems that installing Ruby via Home Brew was giving some problems when trying to run RSpec so I uninstalled it and installed it again via RVM. Although, as #Mskha said, Rbenv could also be a possible option.

NeoVim does not use ruby specified by rbenv on MacOS

I have the following environment setup
OS: macOS Catalina 10.15.7
Zsh: 5.8
Neovim: 0.4.4
rbenv: 1.1.2
$ rbenv local
2.7.1
$ rbenv global
2.7.1
$ /usr/bin/ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
RBENV_VERSION is not set. rbenv-doctor script also fine. Above all the facts, I assumed my rbenv setup is working.
When I am in neovim,
:echo has('ruby')
1
:ruby puts RUBY_VERSION
2.6.3
It should have been 2.7.1 but 2.6.3 (system ruby provided by macOS)
I have started with nvim -u NORC and still getting the same.
What should I check next to make NeoVim picks up rbenv specified ruby?
It cannot be reproduced in another (clean) account.
It was caused by messed up rbenv environment.
rudimentary neovim-ruby-host remained in old ruby version (found out by rbenv whence neovim-ruby-host showing unused ruby version)
rbenv shim (specifically gem) using system provided gem. (rmed the shims and rbenv rehashed)
rbenv doctor was not enough for the troubleshooting. The followings helped me find the cause
gem env and gem env home: showed I was using system provided gem executable
rbenv rehash: removed the staled shims and recreated them
rbenv which neovim-ruby-host: showed actual path of neovim-ruby-host
rbenv whence neovim-ruby-host: showed ruby versions providing the command (in my case incorrect one)

new version of rails installed, rails command not recognized

I want to do a new rails app. I installed ruby 2.4.4 because I cloned a project.
I used to set the new version for the project
rbenv shell 2.4.4
because rbenv local was not working
Now that I am using ruby 2.4.4
system
2.3.4
2.3.5
* 2.4.4 (set by RBENV_VERSION environment variable)
I get following error message:
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.3.4
2.3.5
1) how can I fix this?
2) why is rbenv local not working?
What happens when running rbenv local 2.4.4
~/Local_Documents/CodingArea/personal_projects/zaina-project/zaina_deal_room/zaina-dealroom   setup  ruby -v
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin16]
~/Local_Documents/CodingArea/personal_projects/zaina-project/zaina_deal_room/zaina-dealroom   setup  rbenv local 2.4.4
~/Local_Documents/CodingArea/personal_projects/zaina-project/zaina_deal_room/zaina-dealroom   setup  ruby -v
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin16]
basically it happens nothing. Ruby version 2.3.5 is still selected. I expect to see version 2.4.4 as selected, after running rbenv local 2.4.4. I guess it's something with my ENV, that the version that I have written in a file, takes preferences, but I don't know how to fix this.
in my .zshrc I have:
export RBENV_VERSION=2.3.5 # use rbenv rehash
export ALBERT=8
export PATH="$HOME/.rbenv/bin:$PATH:./node_modules/.bin"
Is it wrong to have the ruby version there? is my PATH correct?
So, rbenv local 2.4.4 will never be applied because of export RBENV_VERSION right?
At a high level, rbenv intercepts Ruby commands using shim executables injected into your PATH, determines which Ruby version has been specified by your application, and passes your commands along to the correct Ruby installation.
When you run a command like ruby or rake, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable called PATH, with each directory in the list separated by a colon: /usr/local/bin:/usr/bin:/bin
Once rbenv has determined which version of Ruby your application has specified, it passes the command along to the corresponding Ruby installation.
Each Ruby version is installed into its own directory under ~/.rbenv/versions. For example, you might have these versions installed: ~/.rbenv/versions/1.8.7-p371/
So, for each ruby version you must install two gems:
gem install bundler
gem install rails
About how to fix rbenv you can read in this question.

rbenv cannot run gem command

Im using rbenv as my ruby versioning manager, I run these commands:
$ rbenv install 2.2.2
$ rbenv global 2.2.2
$ rbenv rehash
$ ruby -v
$ > ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin11.0]
but when I run this command:
$ gem -v
it returns an error:
/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv-exec:
/Users/username/.rbenv/versions/2.2.2/bin/gem: /Users/mac/.rbenv/versions/2.2.2/bin/ruby: bad interpreter: No such file or directory
/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv-exec: line 43: /Users/username/.rbenv/versions/2.2.2/bin/gem: Undefined error: 0
What do I miss? thanks in advance
I could not figure the problem out. I was using homebrew and uninstalled it. Reinstalled directly and it's working now.

RVM : cannot find installed ruby

When i cd into a project with .ruby-version file i get an error about corresponding ruby version not installed.
$ cd my-app/
ruby-2.0.0p451 is not installed.
To install do: 'rvm install ruby-2.0.0p451'
I installed it with RVM and still have the error.
More info :
I have rvm installed and i got it working without problem for some time. I recently needed ruby-2.0.0p451 for a project, after installing i was able to use it :
$ ruby --version
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin12.5.0]
But when i add a .ruby-version file it seems RVM cannot find ruby
Here is a copy of my .bashrc and bash_profile

Resources