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)
Related
How can I switch from using the version of Ruby that comes with MacOS to the most recent version of Ruby that I downloaded using Homebrew?
My version of MacOS appears to have ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18] already installed with the system at usr/bin/ruby. I tried running brew install ruby to get the most recent version of Ruby however when I run ruby -v the same old version shows up. I figured I probably had to add it to my path so I went to my ~/.bash_profile and added
export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
but still ruby -v shows the old version. I closed the terminal, reopened the terminal, ran source ~/.bash_profile with no luck.
Figured out my mistake.
export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
Should have been
export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
then just run
source ~/.bash_profile
and confirm with ruby -v or type -a ruby
#prettycoder's answer almost did it for me. I needed to do an rbenv init as well to get the proper version of ruby when running ruby -v:
brew install rbenv
brew upgrade ruby-build
rbenv install 2.6.5
rbenv global 2.6.5
or
rbenv local 2.6.5
rbenv init
I would recommend using a version manager, e.g. rbenv
brew install rbenv
brew upgrade ruby-build
rbenv install 2.6.1
rbenv global 2.6.1
or
rbenv local 2.6.1
Details about rbenv here: https://github.com/rbenv/rbenv
Instead of
export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
It is better to use this
export PATH="/usr/local/opt/ruby/bin:$PATH"
Which is a symbolic link of ../Cellar/ruby/2.6.1. You can use readlink to print it.
Then you don't need to worry about upgrading ruby.
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.
I have gone about the recommended way of installing a new version of Ruby on Mac OS X: Homebrew, and rvm. I ran rbenv to install Ruby 2.3.3, and selected it as the preferred version by using "rbenv global 2.3.3". The problem I am having is that there is currently a 2.0.0 version installed at /usr/bin/ruby, and for some crazy reason I am unable to remove it.
$ rbenv global
2.3.3
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
$ ~/.rbenv/versions/2.3.3/bin/ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
sudo rm -rf /usr/bin/ruby
Password:
rm: /usr/bin/ruby: Operation not permitted
Argh!! Please help.
The problem is not your system Ruby, the problem is you probably didn't follow the rbenv installation instructions completely correctly.
The reason the system Ruby is located before your rbenv Ruby, is because your PATH has not been properly updated.
This explains why that is important:
https://github.com/rbenv/rbenv#understanding-path
To set up your PATH correctly you can read and complete steps 2-4 here:
https://github.com/rbenv/rbenv#basic-github-checkout
So I am using rbenv to set my ruby version (for the specific project I'm working on this is 2.1.1). The issue is that bundler is unable to detect this change. I even tried to set the version in my gemfile:
source "https://my-proxy-address"
ruby "2.1.1"
gem 'fileutils'
gem 'json'
gem 'chef-api'
However this then causes the exact error message as seen here at the end of the tutorial:
username#hostname:~/Desktop/working-bundler-env$ rbenv version
2.1.1 (set by /Users/username/.rbenv/version)
username#hostname:~/Desktop/working-bundler-env$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin15.0]
username#hostname:~/Desktop/working-bundler-env$ bundle install
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
The tutorial has the solution to the issue (edit a pathfile), however they dont say what file to change. What file do I change?
$ rbenv
rbenv 1.0.0
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
install Install a Ruby version using ruby-build
uninstall Uninstall a specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme
$ which bundle
/usr/local/bin/bundle
So I noticed that when I ran gem bundle install the version was 1.13.3. After running sudo find / -name bundle I found two file locations that included that version number.
/Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle
/Users/myusername/.gems/gems/bundler-1.13.3/lib/bundler/man/bundle
After attempting to run /Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle install it works perfectly. So I just made an alias in my ~/.bash_profile that overwrote the incorrect bundle command.
alias bundle=/Users/alexcohen/.gems/gems/bundler-1.13.3/exe/bundle
The only side effect of this gem (for better or worse) is that it creates .bundle and path directories in the directory where I run bundle install where the gems are downloaded into.
I still have to investigate why this is happening, but I think that the bundle command in my macs terminal was referencing some type of broken bundler gem or file somewhere in my system.
Just trying to update to the latest version of Ruby. On ruby-lang.org/en/documentation/installation/#homebrew, I found that you should be able to do it via homebrew:
brew install ruby
However, when I listed the ruby version (ruby -v) after it 'updated' it was still at the old version 2.0.0.
Hermes:~ Sancho$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]
I happened to list the contents of /usr/local/bin/ and I could see a symbolic link:
ruby -> ../Cellar/ruby/2.2.1/bin/ruby
So, I don't know what's happening and why the version still lists the old number and not 2.2.1, as it looks like it should.
There are sym links to for various other ruby tools (erb, gem, irb, rake, rdoc, ri) to version 2.2.1 also.
So what is happening here and how do I correctly install version 2.2.1?
I do have RVM installed also, but I want to update the system version of ruby to the latest.
Easy step
brew uninstall ruby # (if installed)
brew install ruby
then copy the path and paste into the terminal and restart the terminal
check ruby --version
Use Homebrew but make sure /usr/local/bin is early in your path. Ex:
.bashrc
export PATH=/usr/local/bin:$PATH
This will not update the system Ruby version. Instead it will install another version of ruby and this line tells bash to look for the new version instead.
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
$PATH doesn't change in current Terminal session. So please close the Terminal and reopen.
Ref: Jekyll on macOS