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.
Related
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
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.
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.
I'm trying to install Rails onto my Mac and keep running into a this issue. I have no coding/programming experience and am trying to get set up so I can start learning.
I have gone through everything on install rails.com and am not sure what to do.
Your help is appreciated.
make install failed, exit code 2
Gem files will remain installed in /Users/feferrada/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/feferrada/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.6.2/gem_make.out
Follow the steps below to install ruby on rails on mac osx yosemite.
If that does not work please post the exact errors.
For further details about the installation have a look at https://gorails.com/setup/osx/10.10-yosemite
Installing Homebrew
You might be asked to install the XCode CommandLine Tools - say yes.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installing Ruby
you can browse the available versions using
rbenv install --list
installation using homebrew
brew install rbenv ruby-build
# 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
# Install Ruby
rbenv install 2.2.1
rbenv global 2.2.1
now ruby is installed and you should be able to run
ruby -v
# ruby 2.2.1...
Installing Rails
you can browse the available versions of rails using
gem list ^rails$ --remove --all
installation
gem install rails -v 4.2.1
to use the rails command run
rbenv rehash
now rails is installed and you should be able run
rails -v
# Rails 4.2.1
I decided to clean up my development laptop in preparation for chef.
I ran:
gem clean
sudo gem clean
/usr/bin/gem list --no-versions | xargs sudo /usr/bin/gem uninstall -a
Then I noticed that I don't have ~/.bashrc so I ran
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
~/.bashrc is a blank file otherwise. Next, I pull the rbenv git and ran:
rbenv install 2.1.0
rbenv rehash
rbenv global 2.1.0
ruby -v # ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
gem -v # 2.2.0
bundle install works fine in two projects after this.
Finally,
gem install knife-solo berkshelf --debug -V
produces
Exception `LoadError' at /home/mark/.rbenv/versions/2.2.0-dev/lib/ruby/2.2.0/resolv.rb:169 - LoadError
Exception `Errno::EEXIST' at /home/mark/.rbenv/versions/2.2.0-dev/lib/ruby/2.2.0/fileutils.rb:250 - File exists # dir_s_mkdir - /home/mark/.gem/specs/api.rubygems.org%443
Exception `Errno::ENOENT' at /home/mark/.rbenv/versions/2.2.0-dev/lib/ruby/2.2.0/rubygems/remote_fetcher.rb:286 - No such file or directory # rb_file_s_stat - /home/mark/.gem/specs/api.rubygems.org%443/latest_specs.4.8
GET https://api.rubygems.org/latest_specs.4.8.gz
Exception `OpenSSL::SSL::SSLErrorWaitReadable' at /home/mark/.rbenv/versions/2.2.0-dev/lib/ruby/2.2.0/openssl/buffering.rb:182 - read would block 302 Moved Temporarily
OpenSSL seems to be installed fine and I can't seem to find any info on this error.
Environment: Ubuntu 13.10, Rails 4.0.0
This finally worked after I removed my ~/.rbenv folder and started again. I had previously removed the native system ruby using apt-get and I'm not sure if this was the error. I'm unsure if a system version of Ruby is required or not but it all worked after I used sudo apt-get install ruby.