I'm tryng to install rails with gem install rails but when I try that I get
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
So I tried using sudo gem install rails and I get
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
I've checked on the internet and it says I should install RVM but when I try to do that it tells me :
Error running './configure --prefix=/Users/manhattan/.rvm/rubies/ruby-2.7.0 --with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/libksba:/usr/local/opt/readline:/usr/local/opt/zlib:/usr/local/opt/openssl#1.1 --disable-install-doc --enable-shared', please read /Users/manhattan/.rvm/log/1589107425_ruby-2.7.0/configure.log There has been an error while running configure. Halting the installation.
Could someone help me please.
Installing Ruby gems (like Rails) on a Mac is a common source of confusion and frustration. Unfortunately, most solutions are incomplete, outdated, and provide bad advice. You should never need to use sudo or change permissions.
I wrote an article explaining why you should never use sudo to install gems.
This write permissions error is very common, and is due to trying to install Rails using the system Ruby (the version of Ruby that came preinstalled on your Mac). Learn why you shouldn't use the system Ruby to install gems on a Mac.
There are many questions on Stack Overflow about this permissions error, and the solution is the same. So, instead of repeating myself, I'll just link to my popular answer (480+ votes) here:
https://stackoverflow.com/a/54873916/928191
you can change the permission of the directory you are working on
# chmod -R 777 DIR_NAME
# cd DIR_NAME
# gem install rails
Related
Being really new to Ruby/Rails, and after attempting to resolve the issue myself this weekend I'm making an attempt to seek advice here.
I have a complete Ruby/Apache/Passenger setup done on FreeBSD, and I'm trying to accomplish the task of using Windows as a Ruby development environment.
So far:
Ruby is installed, v2.0.0p0 (2013-02-24) [x64-ming32]
Rails is installed, v.3.2.12
I have the Ruby dev kit installed and registered.
I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)
I can start a rails server successfully, and continuing with the http://guides.rubyonrails.org/getting_started.html tutorial to 3.3.
">rake db:create" tells me:
Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (
sqlite3 is not part of the bundle. Add it to Gemfile.)
which I have no "understanding" of. Trying to install activerecord-sqlite3-adapter gives me a "Could not find a valid gem..."
">gem install sqlite3" returns:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
D:/Development/Ruby200-x64/bin/ruby.exe extconf.rb
checking for sqlite3.h... *** extconf.rb failed ***
Right now I'm stuck at the point where I don't even know what state my Ruby on Windows installation is in. I'm trying to follow the main Rails tutorial and it doesn't specify any of these issues (probably because Ruby on Windows seems to be a natural pain for a lot of people.)
What am I missing?!? I'm just trying to install sqlite3 for Ruby on Windows, seems simple right?
If I do ">rais db" the SQLite shell is presented:
SQLite version 3.7.15.2 2013-01-09 11:53:05
Similar questions with steps that do not resolve my issue:
Installing SQLite 3.6 On Windows 7
Even though the question has been answered, I want to post my research to help others. I found a lot of information online, but being a Ruby newbie I had a tough time following all. The basic answer comes from the following post https://github.com/luislavena/sqlite3-ruby/issues/82 with instructions by "paulwis" on how to properly install sqlite3 for ruby 2.0.0-p0 and some comments on https://github.com/rails/rails/issues/10150 . So here it is:
Install the Ruby Devkit for your setup (DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe for me since I use a x64 machine)
Download and extract the autoconf package from Sqlite.org
Run msys.bat (it is inside the ruby devkit root folder)
cd into the path where you downloaded the sqlite source (for example: "cd /c/dev/sqlite3" for path "c:\dev\sqlite3" if you are new to MSYS/MINGW32)
Run "./configure"
Run "make"
Run "make install"
Get the sqlite3 gem again, this time specifying the platform and the path to the newly compiled binaries:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]
For example:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/c:/dev/sqlite3/ --with-sqlite3-lib=/c:/dev/sqlite3/.libs/
(from the paths given in step 4)
Check the Gemfile.lock of your rails app and make sure that it points to the correct sqlite3 version. Mine was "sqlite3 (1.3.7-x86-mingw32)" and manually changed it to "sqlite3 (1.3.7-x64-mingw32)". Removing the platform also works: "sqlite3 (1.3.7)".
This is an old thread, but still relevant.
For us it was as simple as editing the Gemfile and adding a specific version for sqlite.
gem 'sqlite3', '~> 1.3.13'
I was able to install sqlite3 with ruby2.0.0 on win XP32 with following command:
c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite
Folder C:/distr/sqlite contains following files
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h
sqlite3.def
sqlite3.dll
So, basically I've extract sqlite-amalgamation-3071602.zip and sqlite-dll-win32-x86-3071602.zip to C:/distr/sqlite.
HEADS UP
You still need to put copy of sqlite3.dll and sqlite3.def somewhere to PATH. IMHO it's best to keep sqlite3 binaries in ruby's bin folder.
#!/usr/bin/env sh
mkdir c:/sqlite3x86
wget -P c:/sqlite3x86 http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
cd c:/sqlite3x86
bsdtar --lzma -xf c:/sqlite3x86/sqlite-3.7.15.2-x86-windows.tar.lzma
gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite3x86
cd c:/
rm -rf c:/sqlite3x86
For windows,
go to C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb
and make sure
require "sqlite3" instead of native
Get the fat binary from here
https://ci.appveyor.com/project/MSP-Greg/sqlite3-ruby/build/3/job/hhk6ie8gdo545svr/artifacts
and
gem install c:\path\to\downloaded_gem.gem
You should follow this procedure:
gem install bundler
(add in Gem file_)
gem 'sqlite3', ' < 1.4'(add in Gem file_)
then run:
install bundler
I figured I'd put in an answer -- from the comments, for posterity's sake. The issue seemed to be that I grabbed a new version of Ruby/Rails (for Windows) that was not compatible "yet" with SQLite3.
I downgraded to 1.9.x and was able to things running.
The easiest way to get set up for Ruby on Rails on a Windows machine is by using the RailsInstaller, which automatically installs and configures sqlite3 for you. One step.
http://railsinstaller.org/en
I want to install ruby on rails in offline mode (i.e. without internet connection). So I downloaded railsinstaller-3.2.0.exe from http://railsinstaller.org/en and installed it. By the end, I had ruby installed but in order to have rails installed I ran
gem install rails
and faced these errors: (meaning command needs internet connection)
ERROR: Loading command: install (ArgumentError)
unknown encoding name - CP720
ERROR: While executing gem ... (NoMethodError)
undefined method 'invoke_with_build_args' for nil:NilClass
I mean is there any solution like downloading gems with another computer connected to internet and then copying files in the proper location in the installed directory of gems.
Please help me if you have any idea.
As said in a comment, it's a gem (lib) dependency issue.
You might want to look into installing the bundler gem library to manage dependencies for you, with bundler you would just have to run, bundle install and it would download all the required gems for you including any gem dependencies.
You can install bundler simply, just run
gem install bundler
Then in your rails project directory, just run bundle install.
Often to run a project (like rails for example) you might have to start it with
bundle exec rails start
To install Gem's on a non-internet connect computer you might want to refer to this answer on just that problem.
This is the website where you can find all available ruby gems. Ruby
gems download. Find the one you are interested and download it.
Then move the gem in a directory of your choice and cd into that from
the command prompt. I am using C:/ruby193/bin/pony-1.4.gem
Let's say that the gem we are interested in is the pony gem (smtp
email).
Just type gem install pony-1.4.gem
and you should get it installed manually unless you have a restricted
acc with not adequate administrative privileges.
You can also refer to the official documentation on the matter.
I've read all the other Stackoverflow posts on this problem but don't see any suitable solution for rbenv, so i'll post it on here. (most of the other posts suggest either using RVM, or the OP had already ran sudo gem install rails).
when i run gem install rails (without sudo), i get
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
is /Library/Ruby/Gems/2.0.0 the correct spot?
why am i getting this error? i'm on a fresh laptop that hasn't had much install.
i've got homebrew, rbenv, and ruby 2.0
rbenv should not be trying to install to your System install of Ruby. If you check the permissions on /Library/Ruby/Gems/2.0.0 you'll see it's owned by root, which means you'll need to sudo to write to it, which we're trying to avoid.
This suggests that either
There is something wrong with your rbenv installation, because it should be looking at /Users/whoami/.rbenv/versions/2.0.0. As you can see in their documentation. I'd confirm that your rbenv is operating correctly or maybe try reinstalling to make sure your rbenv installation of ruby is taking priority.
Your system ruby might be clobbering your rbenv. Have you made sure that your system ruby isn't taking precedence in your path? Try running gem list rake -d with a gem you already have installed to see where your gems are currently installed
was hoping someone could point me in the right direction as I am unable to find a previously posted answer to my question of trying to install rails on my mac mini running Lion OSX 10.7.3. I have ruby version 1.8.7 and rvm 1.12.5 but when I come to install rails using sudo gem install rails I get the following:
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.7.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.7.0/ext/json/ext/parser/gem_make.out
The content of gem_make.out are:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
which did not really help me so not sure what it is I am missing? Any help or directions to help me solve this problem would be appreciated. Many thanks.
rvm is not intended to be used with sudo except during a multi-user installation - try simply gem install rails. Even better, rvm now has a guided rails install,
curl -L get.rvm.io | bash -s stable --rails
Take a look at RVM installation page for more details. If you're still having trouble, post the commands you're trying. The #rvm channel on irc.freenode.net is very helpful too.
In order to build Ruby and many other gems you'll need a working compiler. Unfortunately Apple has made this quite complex so there's a command in rvm to help: rvm requirements
you should not use sudo gem ... it basically looses your environment settings and prevents you from using RVM.
Please follow #tantrix instructions.
Sounds like you'll need to install XCode on your machine to get the necessary header files for building the Rails gem. It's a huge installation, unfortunately.
There was, at one point, a way to load (e.g.) the stuff on your machine that you need to build Rails without installing XCode, but I can't seem to locate it at the moment.
In my case,
I run rvm requirements and it helps me install gcc.
But the problem still exists and only solved after I restarted osx.
I tried to install the new beta on my system with the command:
sudo gem install rails --pre
but no matter what I tried, I still get this damn error:
Successfully installed
rails-3.0.0.beta3 1 gem
installed Installing ri
documentation for
rails-3.0.0.beta3... File not
found: lib
Since I'm very new to ruby, I really don't know what to do.
How can I finish installing this?
Is this installed already?
Why does it abort here?
All you need to run is gem install rdoc, follow its instructions, then run the install rails command again and you're good. The problem is due to rdoc failing to install when installed with rails, if installed manually it works fine.
Source: http://gist.github.com/565967
^ I had the same problem, and this worked for me.
If you're looking to do ruby/rails development on Mac, I'd strongly recommend not using the version of ruby/rubygems shipped with your mac. What I do recommend is:
Installing homebrew and using that to manage software packages on your mac.
Install brewbygems, which makes homebrew play nice with rubygems: gem install brewbygems
Install rvm and learn to love the different versions of ruby and rvm's gemsets feature: gem install rvm
Once you've done that you'll have a pretty robust development environment and you should be able to install any version of rails without a problem. Just keep in mind rails 3 works best using ruby 1.9.2 (install with rvm by running rvm install ruby-head) and is still in beta, meaning it isn't terribly stable and should not be used for anything production grade (yet).
I found the same error message, while after some google I've successfully installed it by manually 'sudo mkdir lib' in the .../gems/rails-3.0.0.beta3. Though it hasn't raised further problem, I hope someone could tell what should be in the missing lib directory.
You don't really need to do this sudo gem install rails --pre, simply sudo gem install rails. Rails3 is the default package now and out of beta.
It should work fine.
Might be a different solution on your OS, but I got the same exact error in Ubuntu and creating a ¨lib¨ folder under the rails gem folder solved my problem. I have explained the solution in the following post:
Installing Rails: "File not found: lib"
For convenience I will copy it here as well. The solution:
mkdir /lib/ruby/gems/1.8/gems/rails-{whatever your version is}/lib
Explanation: The ¨[sudo] gem install rails¨ command expects the /lib folder (at the end) but for some reason it hasn´t been created yet.
The original source of this solution was the following URL. Hope it helps!
http://www.spritle.com/blogs/?p=915
Same problem with beta 4.
The workaround is sudo gem install rails --pre --no-ri --no-rdoc though I don't know why.