So when I run:
$ rails new mywebapp
I get the following error:
Your user account isn't allowed to install to the system Rubygems.
This is despite installing rbenv via Homebrew.
I have added the following to ~/.bash_profile
eval "$(rbenv init -)"
And installed a version of Ruby.
Running:
$ echo $PATH
Gives me:
/Users/myusername/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Im not sure where to go from here. Hoping someone can help.
Many thanks.
Agreeing with Dylan on the problem, I think that the best solution is to set explicitly an Rbenv global version using rbenv global 2.1.1
And then reinstalling bundler on that version.
gem uninstall bundler
gem install bundler
rbenv rehash
This worked good for me.
Hope it helps.
Based on the comments to the original question, the answer was that the system-installed rails executable was being used instead of the rbenv version. The fix was to run:
gem install rails
Related
I am getting this error while running server, how do I fix this?
You better install Ruby 2.2.5 for compatibility. The Ruby version in your local machine is different from the one declared in Gemfile.
If you're using rvm:
rvm install 2.2.5
rvm use 2.2.5
else if you're using rbenv:
rbenv install 2.2.5
rbenv local 2.2.5
else if you can not change ruby version by rbenv,
read here
If you have already installed 2.2.5 and set as current ruby version, but still showing the same error even if the Ruby version 2.3.0 is not even installed, then just install the bundler.
gem install bundler
and then:
bundle install
If you are using rbenv then make sure that you run the "rbenv rehash" command after you set local or global ruby version. It solved the issue for me.
rbenv rehash
Your Gemfile has a line reading
ruby '2.2.5'
Change it to
ruby '2.3.0'
Then run
bundle install
Had same issue. I'm using rbenv and which ruby would show the rbenv version:
/Users/Mahmoud/.rbenv/shims/ruby
which bundle though would show:
/usr/local/bin/bundle
After looking in every possible place, turns out my problem was that I needed to update path in ~/.zshrc in addition to ~/.bash_profile (where I originally had the changes)
if you're running zsh add those two lines in ~/.zshrc (or the equivalent file) in addition to ~/.bash_profile
export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"
After saving, quit terminal and relaunch before retrying. Hopefully this would help.
Two steps worked for me:
gem install bundler
bundle install --redownload # Forces a redownload of all gems on the gemfile, assigning them to the new bundler
A problem I had on my Mac using rbenv was that when I first set it up, it loaded a bunch of ruby executables in /usr/local/bin - these executables loaded the system ruby, rather than the current version.
If you run
which bundle
And it shows /usr/local/bin/bundle you may have this issue.
Search through /usr/local/bin and delete any files that start with #!/user/bin ruby
Then run
rbenv rehash
I had this problem but I solved it by installing the version of the ruby that is specified in my gem file using the RVM
rvm install (ruby version)
After the installation, I use the following command to use the the version that you installed.
rvm --default use (ruby version)
You have to install bundler by using the following command in order to use the latest version
gem install bundler
After the above steps, you can now run following command to install the gems specified on the gemfile
bundle install
it can also be in your capistrano config (Capfile):
set :rbenv_ruby, "2.7.1"
Add the following to your Gemfile
ruby '2.3.0'
I am on Mac OS Sierra. I had to update /etc/paths and add /Users/my.username/.rbenv/shims to the top of the list.
If you have some dependency on the version of the Ruby , then install the appropriate version. otherwise change the version in the gemfile in the current directory.
rbenv install <required version>
rbenv local <required version>
Even after installation it was showing the same error for me, so I just restart the mac, then do the bundle install, it works :)
it should show something like this
<user>#<repo>% rbenv versions
system
* 2.3.7 (set by <app>)
For $ Your Ruby version is 2.3.0, but your Gemfile specified 2.4.1.
Changed 2.4.1 in Gemfile to 2.3.0
Refer the below link to install the required version.
https://nrogap.medium.com/install-rvm-in-macos-step-by-step-d3b3c236953b
$ \curl -sSL https://get.rvm.io | bash
rvm install 2.7.1
run:
rbenv global
if old version
then run:
1)
brew update
brew install ruby-build
2)
brew install rbenv
3)
rbenv install 2.7.5
4)
rbenv init
5)
rbenv shell 2.7.5
6)
eval "$(rbenv init - zsh)"
list commands for rbenv - run simple:
rbenv
I install rvm and rbenv it not help me so i go the project and open Gemfile change the ruby version with recommend version and than follow the command cd ios -> bundle install
Your project is ready to Run now.
Open Gemfile and find
ruby '2.2.5'
Change it to
ruby '2.3.0'
then install bundle
I am literally new to Ruby. This is my first day and naturally it starts with installing it on my machine.
I am using Mac os El Capitan. It already shipped with ruby so I just updated it, installed the rvm & gem and tried to install rails using the following commands:
rvm get head
sudo gem update --system
sudo gem install rails
The last command (installing rails) is giving me the following error:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/rackup
Any idea what is it and how to fix it? I have found couple of questions on stackoverflow with similar, but not the same error, but I didn't even understand the answers. Again I am really a novice here.
Edit:
I keep getting comments that this is a duplicate question. However it is not giving me the same error as in the other questions.
Please if anyone knows what is this error about, or whether it's really the same error, explain why, otherwise I don't see a reason why you should mark the question as duplicate without understanding the error message.
My advice is to install rbenv. Later you can easily switch between ruby versions
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.3.1
rbenv global 2.3.1
ruby -v
And then install rails
gem install rails -v 4.2.6
rbenv rehash
rails -v
# Rails 4.2.6
I am using Rbenv to manage my ruby versions, and don't remember ever having an issue before. It's been a while since I developed at home though.
Basically this is what happens:
➣ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
➣ rbenv local
2.3.1
➣ rbenv global
2.3.1
Really not sure what I'm missing. Never seen this issue before.
#rPat, what does the command
$ which gem
reveal? If it indicates you're using the the system gem command, try
$ rbenv rehash
and see if that resolves the issue.
Also make sure
eval "$(rbenv init -)"
is in your .bash_profile
You're using the system version at the moment, and it sounds like you want to use a private Ruby. First, make sure that you have the current rbenv version by following the Upgrading instructions.
When you have the most recent version of rbenv, pick a version of Ruby that you want to use (e.g. 2.2.5) and run:
rbenv install 2.2.5
This will install that Ruby version privately.
Next, you can set the version to use, by default, run this to set the Ruby version as your local default:
rbenv local 2.2.5
And that should get you up and running.
Am trying to set up rails on mac using rbenv and Homebrew.
Currently getting the following message when attempting to 'gem install rails':
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
username-mbp:projects username$ gem install rails
Any ideas??
If you are using rbenv, you should not use sudo to install gems. rbenv very helpfully installs your gems under your home directory in a way that allows you to use different gems for each installed Ruby version. When you change versions of Ruby you will really appreciate this.
To see the current version of Ruby, use rbenv local. For me this prints:
2.2.2
To see all the Ruby versions on your system of which rbenv is aware:
rbenv versions
rbenv stores the version specifier in a file called .ruby-version. This allows you to use different versions of Ruby for different projects, each version having its own set of gems.
When you try to install rails and get the Gem::FilePermissionError, it means that rbenv is not active, or you are deliberately installing into the "system" Ruby. There is nothing wrong with this per se, but you are not taking advantage of rbenv.
I recommend installing Rails again, using rbenv local to ensure that you are adding the gems to the correct path. You'll know this is working when
gem env gemdir
produces something like:
/Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
See https://github.com/sstephenson/rbenv#installation for more info.
This probably means that you used sudoat some point, which means that you run a command that allows you (as a permitted user to execute a command as the superuser or another user) See here: http://linux.about.com/od/commands/l/blcmdl8_sudo.htm.
Can you please paste the commands you used for installing rbenv, ruby, gem, brew, etc.? Also please paste the output of brew doctorto see if environment is correctly configured for Homebrew. Also, please paste the OSX version and rbenv versionsif rbenv is installed.
The steps for installing ruby on rails on OSX are:
Install Homebrew by:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`` (as seen here: http://brew.sh/). Run brew doctor and brew updateto see if everything is fine.
Install ruby: OS X comes with Ruby installed (Mavericks/Yosemite even gets version 2.0.0, previously it was only 1.8.7).
Install rbenv: it can be done either by GitHub Checkout or Brew. You probably should use brew. Run brew install rbenv ruby-build(this will also install ruby-build -https://github.com/sstephenson/ruby-build#readme-). You can also use this command brew install rbenv ruby-build rbenv-gem-rehash. Then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile (to enable shims and autocompletion). You should problably run this too: echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile. Close terminal and open it again. Install the preferred version of ruby (if you want): rbenv install 2.0.0-p353.
Install Bundler: gem install bundler.
Install SQLite: gem install sqlite3
Install Rails: gem install rails.
So, the error you are having is due to permissions (you can understand about them here: http://www.tutorialspoint.com/unix/unix-file-permission.htm). Many people suggest fixing the issue with sudo or chown (http://www.cyberciti.biz/faq/how-to-use-chmod-and-chown-command/). I don't recommend that as it messes with system configuration. It will be better that you run:
rbenv install 2.1.2
rbenv global 2.1.2
gem update --system
When I run with this error like a year ago, what I did was uninstall everything and start again... but, probably that'll take too long.
These links might help you:
ruby for mac, ruby rbenv, rbenv githube, rubies and gems, question on stack
Use sudo:
sudo gem install rails
This guide helped me a lot: Setup Ruby On Rails on
Mac OS X 10.10 Yosemite
I've read and tried the suggestions in several, other, questions, like mine (all with accepted answers) as well as a few more hours of Google searching, but nothing worked. That leads me to think my issue is something corrupt with a piece of Ruby/RBENV ecosystem on my computer or maybe a dreaded PATH issue. I always have to run sudo to install any gems, which I've never had to do before, so that's puzzling too.
Here are some outputs of files & commands I think are relevant. If you need more information, please let me know:
.zshrc
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" if which rbenv > /dev/null;
then eval "$(rbenv init - zsh)"; fi
ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
rbenv local
2.1.1
Gemfile (I've also blown out my gemfile.lock several times too)
source 'https://rubygems.org'
ruby '2.1.1'
gem 'rails', '4.1.4'
... [omitted for brevity]
.ruby-version
2.1.1
echo $PATH
/[user path]/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
I'd be grateful if anyone has any ideas about what I should try next, short of reformatting my computer.
EDIT 1: Tried option B installing both of them from their git repos below as per Ben Kreeger. type rbenv correctly returned rbenv is a shell function and the original message kept appearing. I reinstalled Mavericks and my setup still isn't working.
EDIT 2: Any time I try to install a gem, I get a Gem::FilePermissionError saying I don't have access to the Ruby 2.0.0 folder (installed as system). Going to fiddle with RBENV some more...
EDIT 3: More debugging (everything below)
Kept erroring when installing Ruby versions with RBENV and found some people mentioning readline issues.
Tried the following steps to fix readline: https://github.com/sstephenson/ruby-build/issues/550#issuecomment-40681557, and got an error that my Xcode command line tool install was bad.
Ran xcode-select --install to reinstall them.
Tried rbenv install 2.1.1 again, and got The Ruby openssl extension was not compiled. Missing the OpenSSL lib?
As per https://coderwall.com/p/n9bnug, I linked my OpenSSL extension with https://coderwall.com/p/n9bnug
Reset versions of Ruby: rbenv local 2.1.1 rbenv global 2.1.1 and rbenv rehash
Everything seems to indicate bundler is trying to use my system Ruby install (2.0.0-p247) instead of what RBENV is specifying. Baffled where the missing link is.
WOW, JUST WOW.
All I had to do was gem install bundler and then rbenv rehash. Everything worked.
The original error message pointed me to a problem with RBENV or my Ruby version when in reality it was just falling back on an old version of bundler.
Why wouldn't I have received the more standard this needs bundler version [xxxx]... error instead of telling me my Ruby version is specified incorrectly?
If you're having to use sudo to install gems, then something's likely wrong with your rbenv installation. I'm of the opinion that if you're on OS X and you have to run sudo to install gems or packages, you're doing it wrong (especially if you've got homebrew installed)! You've got two options —
Option A: Alter your .zshrc to be a little more friendly with your $PATH and your rbenv settings. Note here that /usr/local/bin is just being prepended to $PATH, which itself is going to set to a proper default by your system (Mavericks). Make those two lines you posted look like this:
export PATH="/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Then ensure that you close any and all shells and open new ones to load the new settings. Then when you run echo $PATH it should look similar to...
[home path]/.rbenv/shims:[home path]/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Option B: Since I'm more familiar with installing rbenv via git, you may try nuking your homebrew-installed rbenv installation by brew remove rbenv, and follow the directions specified on rbenv's github page (and don't forget to install ruby-build as well). This includes removing any rbenv-specific lines in your .zshrc and setting them to what rbenv recommends.
You can always check the sanity of your rbenv installation by running type rbenv at a command prompt. If all is well, you should at least be getting back "rbenv is a function".
I solved this by running first
rbenv shell --unset
Then I was able to set the version via
rbenv local <ruby_version>