Installing Ruby on Rails on a new Mac OS Sierra - ruby-on-rails

I am learning to code and trying to make the move for a Rails project from a cloud dev environment to a local one on my Mac with OS Sierra. However, I am having trouble setting up my ruby version and installing rails.
I have installed Homebrew which I used to install rbenv. Using rbenv I have installed ruby 2.4.0 and set it to local and global. I can see it in .rbenv/versions, however when I check my ruby version I still get 2.0.0
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
When I try and install Rails I get the following;
$ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I am not sure how I utilize the rbenv ruby version in my system to then install rails.

You probably need to add rbenv to your ~/.bash_profile:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Then source it:
source ~/.bash_profile
Then you can use the rbenv command:
# install a Ruby version:
$ rbenv install <version>
# show versions currently installed and indicate current version
$ rbenv versions
# set ruby version for a specific dir
$ rbenv local <version>
# set ruby version globally
$ rbenv global <version>
# list all available versions:
$ rbenv install -l
The rbenv command is used to install, switch between versions, etc.

Related

Problems installing "rails" in Ubuntu

I am new to programming and trying to install Rails on Ubuntu 18.10, but I get the following error when running ~$ gem install rails. How do I avoid this error and install rails?
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # dir_s_mkdir - /home/bernardo/.gem/specs
I'm running Ruby 2.5.3p105.
Here are the steps that I took to install rbenv in ubuntu server
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv -v
rbenv install 2.5.3
rbenv global 2.5.3
rbenv rehash
ruby -v
gem install bundler
# inside rails application
bundle install
Explanation:
Line 1: clone rbenv project
line 2-4: enter rbenv path and settings to your bashrc
rbenv -v = check whether your rbenv is running correctly
then install ruby version (I checked above you running version 2.5.3)
rbenv global 2.5.3 (set version 2.5.3 in any folder paths)
rbenv rehash (after you set global / local make sure you do rehash)
Just go through the steps given in below link: https://gorails.com/setup/ubuntu/16.04
and make sure you install ruby using rvm and set is default ruby. Then install rails.
This will resolve your issue.
If still the problem is not resolved, then remove previously installed ruby and go through all the steps for ruby and rails installation.
Never install a gem with sudo command.
use
gem install rails
instead of
sudo gem install rails
Use sudo gem install rails May helps you.

Rails is not currently installed on this system - High Sierra, rbenv

To start I follow the exact steps from Setup Ruby On Rails on
macOS 10.13 High Sierra, just like I have with every other version of mac/ubuntu.
So basically install homebrew, install rbenv ruby-build
add the following to bash profile and source it:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
then do
rbenv install 2.5.1
rbenv global 2.5.1
ruby -v
outputs:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
do a which ruby to to make sure:
/Users/pdavies/.rbenv/shims/ruby
run gem install
gem install rails -v 5.2.0
which outputs:
Successfully installed rails-5.2.0
Parsing documentation for rails-5.2.0
Done installing documentation for rails after 0 seconds
1 gem installed
then a rehash and check version:
rbenv rehash
rails -v
outputs:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
found anther issue that suggested adding:
export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"
to the bash profile, did that sourced it and tried again still nothing. to check the output of echo $PATH was:
/Users/pdavies/.rbenv/shims:/Users/pdavies/.rbenv/bin:/Users/pdavies/.rbenv/shims:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin
Just to make sure i also did which gem incase i wasnt using the right one, output:
/Users/pdavies/.rbenv/shims/gem
when I do a which rails i get:
/usr/bin/rails
I found some blog that said to delete that, but I cant seem to do that either, i just get:
sudo rm -f /usr/bin/rails
Password:
rm: /usr/bin/rails: Operation not permitted
This is a fresh install of OSX and the only way I can get it work is to downgrade the version of OSX that is installed, which is a pain in the ass!
Any help would be grateful
Thanks

rails rbenv: rails: command not found

I have recently moved from RVM to Rbenv and when attempting to execute rails I am getting an error like the one below
Pauls-Air:~ $ rails
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.1.2
After installing a gem via the command line in a ruby version you have to execute rbenv rehash as described in the docs here and here
For example:
$ rbenv install 2.2.0
$ gem install bundler
$ rbenv rehash
$ gem install rails
$ rbenv rehash
You need to install Rails for each Ruby version within rbenv. Try running rbenv version, I might expect that 2.1.2 is not the ruby version in use for the current project (local version) or maybe your global version.
I ran into the same issue, but none of these other solutions (or any of the others I found elsewhere) worked. I was about to go back to RVM, so I decided to get rid of rbenv completely and it paved the way to the solution.
Try the following - it worked for me:
uninstalling rbenv, remove all references rbenv in your bash profile, and remove the remaining rbenv file folder and its contents.
Reinstall rbenv with homebrew.
Add it back to your bash profile:
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Restart the shell:
exec $SHELL -l
Check the path:
echo $PATH
Install Rails:
gem install rails
rbenv rehash
Note: I consulted this for part of this answer: https://www.codementor.io/tips/3732499178/solution-for-rbenv-rails-is-not-currently-installed-on-this-system-to-get-the-latest-version-simply-type
Try to set up your environment with 2.1.2 version running this command line in your terminal:
$ rbenv shell 2.1.2
It works to me
Ensure that the .ruby-version file in your project's directory contains the same ruby version as the one you installed with rbenv.
For me, I set up my environment with the listed "The `rails' command exists in these Ruby versions".
$ rbenv shell 2.1.2
$ rails -v
It works.
Like for example if you want to install Ruby 2.5.3 with Rails 6
follow this way:-rbenv global 2.5.3
$ gem update --system
$ rbenv install 2.5.3
$ rbenv global 2.5.3
$ gem install rails -v 6.0.2.2
$ ruby -v
$ rails -v
The problem is that your global ruby version doesn't match your installed somewhere locally version which is 2.1.2. Try executing anywhere in bash shell:
rbenv global 2.1.2
That way rails will be found by rbenv in your $HOME directory and anywhere else.
rbenv global
Sets the global version of Ruby to be used in all shells by writing
the version name to the ~/.rbenv/version file. This version can be
overridden by an application-specific .ruby-version file, or by
setting the RBENV_VERSION environment variable.

Ruby version issues with Rbenv

I am setting up my new machine (Mac Yosemite) and when I run the command "bundle" I get the following error:
Your Ruby version is 2.2.1, but your Gemfile specified 2.2.0
I'm trying to change the version w Rbenv but I think it's not working.
ruby -v
// Ruby 2.2.1p85
rbenv version
// 2.2.0
Can anyone help me? Thanks in advance!
Try to use rbenv local [version number].Refer to this for more understanding.
I had a similar problem but with ruby -v 2.2.0 and Mac OSX El Capitan. What finally worked for me was:
gem install bundler (apparently it was no longer installed)
rbenv rehash
bundle install
I was able to find the answer on the github for rbenv.
https://github.com/sstephenson/rbenv/issues/697
Assuming you have Ruby -v 2.2.0 installed (rbenv install 2.2.0 otherwise), change your ruby version with rbenv:
rbenv global 2.2.0
after install rails you must do this: rbenv rehash, in order to tell rbenv to see rails as executable.
follow this tutorial to set up Ruby and Ruby on Rails in your machine: https://gorails.com/setup/osx/10.10-yosemite
Note: In my case. after install rbenv the command rbenv global 2.2.0 doesn't affect my current ruby version (ruby -v still be the previous one). I fix this issue reinstalling rbenv and run this command:
# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
immediately afterwards, as explained above in the tutorial.

Multiple Ruby and Rails Versions on OS X Yosemite

I'm getting started with Rails development and have a dev environment setup on OS X Yosemite, but the Ruby and Rails versions are a bit wonky. I used homebrew to install Rails, and everything seems to have gone well. Although which rails claims it's located in "~/.rbenv/shims/rails", and not /usr/local/bin where homebrew is supposed to place its apps. There's also /usr/bin/rails which when run yields:
Rails is not currently installed on this system. To get the latest
version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
rails --version returns Rails 4.2.0.
I can create a rails app fine, but when I run rails server the ruby version is ruby 2.1.5 (2014-11-13) [x86_64-darwin14.0].
I followed these instructions (mac-dev-env.patrickbougie.com/ruby-22/) to compile ruby 2.2.0 and ruby --version returns "ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]". which ruby returns "/usr/local/rbenv/shims/ruby".
Relevant lines in .bash_profile from brew install of Rails and compiled ruby 2.2.0 are:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
export PATH=/usr/local/openssl/bin:$PATH export
MANPATH=/usr/local/openssl/ssl/man:$MANPATH export
PATH=/usr/local/rbenv/bin:$PATH export RBENV_ROOT=/usr/local/rbenv
eval "$(rbenv init -)"
How do I get the 2.2.0 version of Ruby to run with Rails? Everything I have read thus far suggests rvm (rvm.io). However, I get homebrew errors when I try to install Ruby that way.
From: http://railsapps.github.io/installrubyonrails-mac.html, section: "If You Already Have RVM Installed"
$ rvm get stable --autolibs=enable
$ rvm install ruby
$ rvm --default use ruby-2.2.0
rvm install ruby throws the homebrew error.
rvm seems unnecessary considering Ruby 2.2.0 is compiled on my machine already.
I appreciate any help, thank you!

Resources