new version of rails installed, rails command not recognized - 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.

Related

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)

How do I get the "bundle install" command to only look at the current version of "ruby" (which I chose)?

I installed Ruby (v2.6.3) and Rails (v5.2.3).
Even completed a training project on this framework.
Then he took up a working project and first of all executed the command bundle install.
All modules were delivered normally, except one "sassc-2.0.1"
Installation fails with this error:
sassc-2.0.1 requires ruby version >= 2.3.3, which is incompatible with the current version, ruby 2.3.1p112
That is, I chose one version, and in fact uses a different version.
I can't understand the reason for this.
But I didn't give up the first time.
I tried to check the ruby version in different ways:
(1) Get ruby version
$> ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
(2) Get path to bin for ruby
$> which ruby
/home/vdenisov/.rvm/rubies/ruby-2.6.3/bin/ruby
(3) Get path to bin for bundle
$> which bundle
/home/vdenisov/.rvm/rubies/ruby-2.6.3/bin/bundle
All these commands give out that the current version of ruby is 2.6.3
However, my friend advised me to do one more check
(4) WTF ???
$> /usr/bin/ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
P.S.: before that I programmed in nodejs and there is a version Manager "nvm" - when you run the command "nvm use a.b.c" in the system, always use the nodejs version of "a.b.c" (the same I expected from the "rvm").
/usr/bin/ruby -v gives you the version of ruby installed in your operating system.
It seems that you already run rvm use --default 2.6.3 because your ruby points to rvm location.
Ruby environment manager RVM supports configuration inside following files: .rvmrc, .versions.conf, .ruby-version, Gemfile. More here: https://rvm.io/workflow/projects
Check these files, it's good practice to set ruby version inside .ruby-version or Gemfile.
bundler gem orients on Ruby version, which locked in Gemfile.lock. Just change Ruby version in Gemfile (not .lock). Try 2.3.3 at first. Maybe you need to install it with rvm or rbenv.

How do I switch my Ruby version for a single project only?

I was reading that rbenv can be used to switch the Ruby environment for a single project only. I have Ruby 2.4 installed on my system, but I'd like to use version 2.3 for a specific project only. I thought using "rbenv local" would heal the pain but it does not ...
localhost:myproject davea$ rbenv local 2.3.0
localhost:myproject davea$ bundle install
Your Ruby version is 2.4.0, but your Gemfile specified 2.3.0
localhost:myproject davea$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
How do I use Ruby 2.3 for this project only?
rbenv local only sets a .ruby-version file in your current directory, it doesn't also load that version for you. You'll need to set it and then cd .. && cd - to have the rbenv shim pick up that version.
If you have a gemfile you can also add
ruby '2.3.1'
inside it to tell your system to use that ruby version.
This is the best solution for a linux or WSL distribution
Check first what the versions you can download
rbenv install -l
then install it with
rbenv install 2.6.6
now you have installed a version to check all version you have:
rbenv versions
then to use it you can set it locally in a specific project:
rbenv local 2.6.6
or globally
rbenv global 2.6.6
After the installation you could create a projet with rails new ==> automaticaly set with ruby global
If the project are alwready created, there 2 ways
Manually modify:
.ruby-version to your global version
or run in folder of the projet rbenv local 2.6.6
What worked for me was #tadman's solution:
rbenv local 2.7.1 # switches to ruby 2.7.1

Specify Path for Installing ruby gem

I have two versions of Ruby installed.
How can I install my ruby gem so that it gets installed in the version specified.
Normally you need to specify which Ruby you're using first, then call the appropriate gem command once that's set.
RVM, rbenv and others all work in different ways. For example, with RVM:
rvm use 2.4.1
gem install xyz -v 1.2.3
For rbenv it's a bit different:
rbenv local 2.4.1
gem install xyz -v 1.2.3
Where that generates a .ruby-version file in your current directory.
Since the gem command itself is Ruby, the proper Ruby environment must be set, which is where the multi-Ruby version managers come in.

Bundler with rbenv version pathfile issue

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.

Resources