Installing rails on ubuntu - ERROR: Failed to build gem native extension - ruby-on-rails

I wanted to start learning ror, but I have problem installing it. Thats what my console says when I type "sudo gem install rails" in.
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
This solved problem:
sudo apt-get install ruby-dev

References : http://railsapps.github.io/installrubyonrails-ubuntu.html
Prepare Your System
You’ll need to prepare your computer with the required system software before installing Ruby on Rails.
You’ll need superuser (root) access to update the system software.
Update your package manager first:
$ sudo apt-get update
This must finish without error or the following step will fail.
Install Curl:
$ sudo apt-get install curl
You’ll use Curl for installing RVM.
Install Ruby Using RVM
Use RVM, the Ruby Version Manager, to install Ruby and manage your Rails versions.
If you have an older version of Ruby installed on your computer, there’s no need to remove it. RVM will leave your “system Ruby” untouched and use your shell to intercept any calls to Ruby. Any older Ruby versions will remain on your system and the RVM version will take precedence.
Ruby 2.3.0 was current when this was written. You can check for the current recommended version of Ruby. RVM will install the newest stable Ruby version.
The RVM website explains how to install RVM. Here’s the simplest way:
$ \curl -L https://get.rvm.io | bash -s stable --ruby
Note the backslash before “curl” (this avoids potential version conflicts).
The “—ruby” flag will install the newest version of Ruby.
RVM includes an “autolibs” option to identify and install system software needed for your operating system. See the article RVM Autolibs: Automatic Dependency Handling and Ruby 2.0 for more information.
If You Already Have RVM Installed
If you already have RVM installed, update it to the latest version and install Ruby:
$ rvm get stable --autolibs=enable
$ rvm install ruby
$ rvm --default use ruby-2.3.0
Installation Troubleshooting and Advice
RVM Troubleshooting
If you have trouble installing Ruby with RVM, you can get help directly from the RVM team using the IRC (Internet Relay Chat) channel #rvm on irc.freenode.net:
http://webchat.freenode.net/?channels=rvm
If you’ve never used IRC, it’s worthwhile to figure out how to use IRC because the RVM team is helpful and friendly. IRC on freenode requires registration (see how to register).

You need a more recent version of Ruby to start with if you are using the latest version of Rails.
Ruby on Rails 4.0 Release Notes
Highlights in Rails 4.0:
Ruby 2.0 preferred; 1.9.3+ required
Whereas in your error message we see:
/usr/bin/ruby1.9.1 . . .
And, in future you should always include in your question the version numbers of all of the software components involved with your problem. It makes focusing on the real issue much simpler for people looking to help you.

Related

What's the best way to run a RoR project on my localhost

I have a friend's website code, which is in Ruby on Rails.
I have tried to install RoR on my Mac using instructions at gorails.com
OS : Mac Mojave
ruby -v : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin18]
rails -v :
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem railties (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/rails:22:in `<main>'
What I tried : I installed ruby, and then rails, using gorails tutorial, and kept getting errors stating version number mismatch.
Keep in mind that creating a new app, worked, but trying to run this existing code is a problem.
So then I uninstalled everything and updated the version using rvm, and since then I am getting this error.
When I cd into the webapp folder and run bundle install, I get errors, such as:
zsh: /Users/abc/.rvm/gems/ruby-2.2.3#hs/bin/bundle: bad interpreter: /Users/abc/.rbenv/versions/2.5.3/bin/ruby: no such file or directory
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your
Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using
RVM are available at rvm.io/packages/openssl.
This project uses a PostgreSQL database, which I have setup already.
If required, I can share the gemfile of this project too.
What is the best way to get this project working?
Am I missing something crucial?
You can't run RVM and RBENV on the same machine. Pick one and remove the other. You're probably best to uninstall both and then pick one, start over.
Uninstall RBENV instructions here or in your case probably brew uninstall rbenv
Uninstall RVM see How can I remove RVM (Ruby Version Manager) from my system?
Close all terminals and then start a new one.
Install RVM see https://rvm.io/rvm/install
Then go to your project, make sure you have the correct ruby version needed by your project. If not, you will need to install with rvm install 2.5.1 for example.
Then run
rvm use 2.5.1 #or some other version
Then you should be able to run bundle install
The rest of the instructions in your link should be ok.

Can't update Ruby resulting in Rails error

I checked the list for http://railsapps.github.io/installrubyonrails-mac.html trying to reinstall Rails and have been trying to update it for the last 2+ hours.
This is what I get at the terminal:
Stevens-MBP:Desktop Steven$ rvm install ruby-2.3.1
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/x86_64/ruby-2.3.1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
==> Upgrading 1 outdated package, with result:
automake 1.15
Error: You must `brew link autoconf` before automake can be installed
Requirements installation failed with status: 1.
Here is additional information:
Stevens-MBP:Desktop Steven$ rails -v
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.
Stevens-MBP:Desktop Steven$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]
Stevens-MBP:Desktop Steven$
When I type sudo gem install rails I get:
ERROR: Error installing rails:
activesupport requires Ruby version >= 2.2.2.
sudo gem install rails
Rule #1 when working with RVM (or rbenv) is do NOT use sudo except for multi-user installs (which are not encouraged by the maintainers).
By default, RVM and rbenv manage Rubies installed using them in a separate folder in your home directory where you already have full privileges to install/update/remove Rubies or gems. Use whichever manager you want to install/remove Ruby and set it as a default, then use gem install ... to install gems.
Using sudo changes your effective user to the sysadmin, which has a different idea where the RVM/rbenv managed Rubies and the associated gems live.
After issuing rvm install ruby-2.3.1 you should do
rvm use 2.3.1 --default
to tell RVM which Ruby you want to use.
rvm info will tell you what RVM knows about its world.
The error you get is probably because your vendor-installed version of Rails is out of date, and sudo is the root-cause of that occurring. Try gem install rails and you should be OK.
First upgrade ruby with rvm upgrade 2.1.2 2.3.1
That should do the trick if you have rvm installed correctly. Once it's done you can install rails with sudo gem install rails

Why do I get a requirements error when trying to install Ruby with RVM?

I would like to install Ruby 2.0 with RVM on my Ubuntu system and get an error message:
rvm 1.23.5 (master)
ubuntu 12.04 (LTS)
**---- Error message: -------**
rvm install 2.0.0
Searching for binary rubies, this might take some time.
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system.....................................................................................................................................
Error running 'requirements_debian_update_system ruby-2.0.0-p247',
please read /home/emzett/.rvm/log/1381812161_ruby-2.0.0-p247/update_system.log
Requirements installation failed with status: 100.
Update the system using:
sudo apt-get update
Try:
rvm remove 2.0.0 # uninstall rvm
rvm get head --autolibs=3 # get the latest RVM and build required libs
rvm requirements # check if there are any dependencies that need to be installed.
rvm install ruby-2.0.0
I solved the problem by editing
etc/apt/source.list.d/medibuntu.list
I just commented the line referring to medibuntu out.
https://gist.github.com/pcjpcj2/5443017
I recommend this gist.
if you need Ruby on Rails 4.0 ~ , best answer is here
I had the same issue. I ran the following command to fix it:
sudo apt-get -f install
Then I remembered that I failed installing a package earlier that day. What this command did was resolve the dependencies on that package and allowed RVM to do its thing.
This happens when there are broken sources in /etc/apt/sources.list.d or /etc/apt/sources.list.d
You can run Ubuntu Software update to see if there are any any failures due to broken sources, if so, follow the below steps
fix them or comment and execute the following steps
rvm requirements -- this will install all of
the required software modules
rvm list -- provides you the available versions of ruby
rvm install ruby-x.x.x -- This will install x.x.x version of ruby, please change the ruby-x.x.x with the version you are interested in ex (ruby-2.1.0 for 2.1.0 version of ruby)

Ruby on Rails install on ubuntu fail. I can has help?

I am trying to install Ruby, RubyGems, and the Ruby on Rails framework so that it will play nicely with my system. I am having issues with my installation. Could somebody help me? Here are the details of my system and how I went about installation.
Currently I am running ubuntu 10.10 using the Linux Kernel 2.6.35-28-generic. My server is Apache 2.2.16 and I use MySQL 5.1.49.
So, I went to my synaptic package manager and selected the following packages to download:
* ruby1.8 – installs Ruby 1.8.4
* libmysql-ruby – additional libraries to access MySQL
* libruby1.8-dbg – debugging library
* ri – Ruby Interactive Reference
* ruby1.8-dev – header files for building extensions
* rails – Ruby On Rails framework
Once that ran successfully, I downloaded rubygems from http://rubyforge.org/projects/rubygems/. Then I unpacked it, got in the terminal, ran a cd to get in the directory of the newly downloaded rubygems directory, and typed 'sudo ruby setup.rb' That ran with no problem and RubyGems 1.8.5 was installed. Then I ran 'sudo gem install rubygems-update' with no problem.
But when I ran 'sudo gem install rails –include-dependencies' I got the following output:
Fetching: activesupport-3.0.8.gem (100%)
Fetching: rails-3.0.8.gem (100%)
Successfully installed activesupport-3.0.8
Successfully installed rails-3.0.8
2 gems installed
Installing ri documentation for activesupport-3.0.8...
Installing ri documentation for rails-3.0.8...
File not found: lib
ERROR: While generating documentation for rails-3.0.8
... MESSAGE: exit
... RDOC args: --ri --op /var/www/testingwww/rubygems-1.8.5/nclude-dependencies/doc/rails-3.0.8/ri lib --title rails-3.0.8 Documentation --quiet
When I run 'rails -v' I get 'Rails 3.0.8' so it seems to have installed despite the error. But when I try to make a rails app by typing 'rails ./helloWorld' I get the manual page for the rails keyword.
I have looked around for two days now on how to fix this issue, but can't seem to figure it out. Does anybody know how to fix this?
Rails 3 requires version 1.8.7 or 1.9.2.
I'd recommend using RVM to manage your Ruby installation and environments. It will really help to get you going quickly and is simple. It's as simple as
curl -L https://get.rvm.io | bash
to install RVM and then rvm install 1.9.2 will get you going.
Have a look at https://rvm.io for more information.
In addition to Matthew's good Answer, I don't know why you're doing rails ./helloWorld. To generate a new app in Rails 3, you should do rails new helloWorld.
If you need a complete guide to getting rolling with Rails under Ubuntu, you can find a short guide here: http://blog.dcxn.com/2011/06/21/rolling-with-rails-3-on-ubuntu-11-04/
The gist is:
Install RVM (The Ruby version manager)
Install Rails from gem
Get going with Rails
It's a simple process but there are a few things you need to do for it to be completely smooth like making sure you have the pre-requisites for rvm installed via apt before install rvm.
Good luck!

Vanishing Ruby Gems

I'm using Ubuntu 8.10 and I installed Ruby and Ruby on Rails following the directions on this site. The exact directions I followed are no longer there as it appears the rubyonrails.org wiki has changed recently. But I installed it the long way. Installed Ruby, then Gems, then installed Rails using "gem install rails".
I haven't really messed with Rails for a while, and I tried to use the Gem command today and...
The program 'gem' can be found in the following packages:
* rubygems1.8
* rubygems1.9
Try: sudo apt-get install <selected package>
bash: gem: command not found
That's just weird to me because I installed rails using the gem command. I have been seaching my computer for the gems binary so I could create a link to it in the bin directory but I can't find it. I know it's installed becaues when I run 'script/server' and go to localhost:3000 in a browser I get the following version information:
Ruby version 1.8.7 (i486-linux)
RubyGems version 1.3.1
Rails version 2.2.2
Active Record version 2.2.2
Action Pack version 2.2.2
Active Resource version 2.2.2
Action Mailer version 2.2.2
Active Support version 2.2.2
Anyone know how I can get my gem command working again? Thanks for any help.
Note: I am new to Rails and fairly new to Ubuntu and Linux in general.
Did you install rubygems from apt-get? If yes, maybe you should try to remove it and install it from source.
Here is another article on installing Rails on Ubuntu:
http://www.rubyinside.com/how-to-install-a-ruby-18-stack-on-ubuntu-810-from-scratch-1566.html
Essentially, you can install Ruby from apt-get or source, but it's recommended to install rubygems from source.
You could look to see if it's in:
/usr/bin/gem1.8
if it is, then symlink /usr/bin/gem to it:
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
BTW, here's another tutorial on how to install rails on Ubuntu 8.10:
http://articles.slicehost.com/2009/1/6/ubuntu-intrepid-ruby-on-rails

Resources