Installing Ruby via rbenv fails - ruby

Problem: I installed ruby, but it is not recognized correctly.
I'm following the deploying to VPS: https://github.com/railscasts/335-deploying-to-a-vps
I am setting my server on ubuntu 12.04 LTS to deploy my rails app. I'm following the railscast on deploying to a VPS, and trying to install ruby through rbenv. It seemed everything was installed correctly, but when I tried to check the ruby version, it gave me errors. The following are the commands that I ran.
deployer#max:~$ rbenv install 1.9.3-p125
Downloading yaml-0.1.4.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /home/deployer/.rbenv/versions/1.9.3-p125
Downloading ruby-1.9.3-p125.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/e3ea86b9d3fc2d3ec867f66969ae3b92
Installing ruby-1.9.3-p125...
Installed ruby-1.9.3-p125 to /home/deployer/.rbenv/versions/1.9.3-p125
Downloading rubygems-1.8.23.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/178b0ebae78dbb46963c51ad29bb6bd9
Installing rubygems-1.8.23...
Installed rubygems-1.8.23 to /home/deployer/.rbenv/versions/1.9.3-p125
deployer#max:~$ rbenv global 1.9.3-p125
deployer#max:~$ ruby -v
'ruby' program can be found in the following packages:
* ruby1.8
* ruby1.9.1
How do I solve this?

You don't need to use rbenv to install a specific version of Ruby. Instead use ruby-build to install 1.9.3-p125 into /usr/local:
ruby-build 1.9.3-p125 /usr/local/
Or, install Ruby manually:
# Compile Ruby (instead of rbenv)
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
sudo make install
sudo gem install bundler --no-ri --no-rdoc

Maybe you are missing
eval "$(rbenv init -)";
in your shell config

You should restart the shell to allow rbenv to find the new Ruby
$ exec $SHELL
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

Related

Installing Compass & Susy on Ubuntu 12.04

I'm trying to install Compass and Susy on my Ubuntu 12.04.
What I have tried are the following steps on the console:
sudo apt-get install rubygems1.8
sudo gem install rubygems-update # Instead of sudo gem update --system
sudo update_rubygems
sudo gem install compass # Installing Compass & Sass
sudo gem install susy
So the gems are installed and will be listed when I do the following command:
gem list
But now, when I try to create a new compass project with
compass create project
I get the following error:
/usr/local/bin/compass: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
My current ruby version is 1.8.7. So I installed ruby 1.9.1 and get it working.
The console still says the current ruby version is 1.8.7
My question: Do I have to run with both ruby versions to get that working? Is there another way under ubuntu? It's working, I know, but it's a bit confusing.
Using Ubuntu's package manager for multiple ruby versions is a bit of a lost cause.
Most people use rvm, which allows you to install and switch between multiple rubies very easily.
Other popular options are rbenv and chruby. It's just a question of personal preference, but I'd say that rvm has the slight edge for beginners.
Also, I wouldn't recommend installing ruby 1.9.1 - it's best to use 1.9.3 as there are some compatibility issues with other 1.9.x versions.
You can then install compass and sass via ruby gems (rather than aptitude):
$ gem install compass
$ gem install sass
This simple command works on ubuntu 14.10
sudo apt-get install ruby-compass
RVM is awesome and really easy to install. I managed to install rvm, compass, and sass with these commands in my terminal:
Firstly:
curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled --ruby=1.9.3
This will instal rvm, it will put a command in ~/.bash_profile to load rvm automatically, except this isn't what Ubuntu uses so put this line into your ~/.bashrc file:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then simply run:
gem install compass
gem install susy #(or sass)
Install build-essentials and ruby-dev packages to install compass without errors.
sudo apt-get install build-essential
sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo gem install compass
Masterchief's answer is close, but didn't work for me. This web page provided a clear and reliably working way to install rvm on my ubuntu server instance: http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/

Failed to build gem native extension when install RedCloth-4.2.9 install Linux

I want to install Octopress in my computer.
I try to do it like
Octopress document.
When I run
bundle install
I got error message
An error occured while installing RedCloth (4.2.9), and Bundler cannot continue.
Make sure that `gem install RedCloth -v '4.2.9'` succeeds before bundling.
So, I run
sudo gem install RedCloth -v '4.2.9'
then, I got a error message again:
ERROR: Error installing RedCloth:
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>'
I hadn't learn any knowledge about ruby.
My ubuntu 12.04 solution is install the ruby1.9.1-full version, that can resolve this issue.
sudo apt-get install ruby1.9.1-full
you can execute command:
sudo update-alternatives --config ruby
to select the altiernative ruby which you have installed.
and then, execute below commands to finish the octopress deploy:
git clone https://github.com/erizhang/octopress.git octopress
cd octopress/
sudo gem install bundler
sudo gem install RedCloth -v '4.2.9'
bundle install
rake install
below commands you can find from octopress deploy guideline page:
rake setup_github_pages
sudo rake setup_github_pages
sudo rake generate
sudo rake deploy
Hope it's helpful for you, thanks
I was installing Octopress too and got the same problem as yours. After checking the mkmf.log file I figured out that gcc-4.2 had not been found. I Even installed xcode with the command line tools. It worked when I made a symlink like this:
$ sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
$ bundle install
I fixed this issue by running
sudo apt-get install ruby-dev
as described in this blog post.
You've probably upgraded to Mountain Lion and have not rebuilt your ruby-1.9.2 install yet with the new development packages.
rvm --force install 1.9.2
gem install bundle --no-ri --no-rdoc
bundle install
If you don't have the Mountain Lion dev packages installed correctly, use the ThoughtBot instructions.
For Ubuntu 14.04 simply do this:
sudo apt-get install ruby1.9.3
Should work for 13.10 and 13.04 too. (Not tested)
it apears you are not using rvm for managing your ruby installation. I think best would be to try rvm, here's a very good guide, you can stop without installing rails: ruby with rvm
Then simply
$gem install RedCloth
Unmanaged ruby gems are a pain, I try to avoid them.
None of the answers worked on my Ubuntu 14.04.1 LTS. Upgrade to ruby 2.0 fixed the problem for me:
sudo apt-get install ruby2.0 ruby2.0-dev
sudo ln -s /usr/bin/ruby2.0 /usr/bin/ruby
sudo ln -s /usr/bin/gem2.0 /usr/bin/gem
sudo gem install bundler
Make sure you also have the build-essential package installed. You can check using
dpkg -l | grep build-essential
or simply install it without checking
sudo apt-get install build-essential
For me on Ubuntu 14.04.1 LTS, after making sure build-essential is installed, the bundle install command works/builds fine also with Ruby 1.9.3.

cannot load such file -- zlib even after using rvm pkg install zlib

I installed zlib package and ruby 1.9.3 using rvm, but whenever I try to install
gems it says
cannot load such file -- zlib
The commands I used to install are
$ rvm install 1.9.3
$ rvm pkg install zlib
$ rvm reinstall 1.9.3 --with-readline-dir=/home/username/.rvm/usr \
--with-iconv-dir=/home/username/.rvm/usr \
--with-zlib-dir=/home/username/.rvm/usr \
--with-openssl-dir=/home/username/.rvm/usr
$ rvm use 1.9.3
$ gem install heroku
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand
All the help on this subject tells me to just do rvm pkg install zlib, and
then reinstall the ruby with --with-zlib-dir=/home/username/.rvm/usr, but this
didn't work.
I ended up installing zlib from apt-get and then reinstalling ruby to not use the rvm directory for zlib.
Here's how do:
$ sudo apt-get install zlib1g-dev
$ rvm reinstall 1.9.3
[Edit] As commenter #chrisfinne mentions, on CentOS/RedHat based systems:
$ sudo yum install zlib-devel
$ rvm reinstall 1.9.3
The both other responses were almost right...
The rvm site for zlib provides a quick fix!
On the top off the page is a "Quick fix" follow it's instructions, it will:
fix your installation,
provide you instructions what to do to install zlib from your system
and show how to reinstall ruby
Use autolibs to install dependencies:
rvm autolibs enable
rvm reinstall 1.9.3
RVM will automatically install missing dependencies and use them for compiling ruby.
More details on autolibs => http://rvm.io/rvm/autolibs
The solution that worked for me is described in rvm github repo, issue #3389.
Run
rvm install 2.3.0 --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8
for ruby 2.3.0 version.
Ruby has a bunch of package dependencies like the one on zlib-devel. They're nasty because there's nothing to indicate you need the library until get some obscure error message while trying to do something routine.
The solution is to use rvm. Use it even if you only need one version of ruby. Why? Because then you can do
rvm requirements
This will probe your particular OS and produce a set of commands you can copy back to the command line to install those missing packages.
rvm pkg install openssl && rvm pkg install zlib && rvm pkg install libyaml &&
rvm pkg install iconv
rvm install 1.9.3-p0 --with-opt-dir=$HOME/.rvm/usr \
--with-libxml2-dir=/usr/local/Cellar/libxml2/2.7.8 \
--with-readline-dir=/usr/local/Cellar/readline/6.2.1

How do I install the latest version of ruby in Ubuntu?

I currently have ruby version 1.8.2 in my machine and I would like to upgrade it to 1.9.2. How am i supposed to do it?
I use Ubuntu, and I've found the easiest way to install newer versions of Ruby is to use rvm.
The instructions are here: https://rvm.io/rvm/install/
Basically, it installs different versions of Ruby locally for the user and updates environment variables for Ruby and gems based on which version you decide to use.
It's this easy:
jim#schubert:~$ rvm use system
Now using system ruby.
jim#schubert:~$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
jim#schubert:~$ gem -v
1.3.7
jim#schubert:~$ rvm use 1.9.2
Using /home/jim/.rvm/gems/ruby-1.9.2-p180
jim#schubert:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
jim#schubert:~$ gem -v
1.5.2
jim#schubert:~$
I don't like having RVM on production server, so I usually install ruby from source with an install script like this:
#!/bin/bash
tmp_dir="/tmp"
version="2.2.3"
minor_version="2.2"
ruby_version="ruby-$version"
echo "*******************"
echo "* Installing Ruby *"
echo "*******************"
sudo apt-get install -y autoconf build-essential libreadline-dev libssl-dev libyaml-dev zlib1g-dev libffi-dev
mkdir -p "$tmp_dir"
cd "$tmp_dir"
wget "http://cache.ruby-lang.org/pub/ruby/$minor_version/$ruby_version.tar.gz"
tar -xvzf $ruby_version.tar.gz
cd $ruby_version
./configure --disable-install-doc
make --jobs `nproc`
sudo make install
cd ..
rm $ruby_version.tar.gz
rm -rf $ruby_version
echo "*******************"
echo "* Ruby installed! *"
echo "*******************"
1 Install RVM:
https://rvm.io
2 Then install Ruby 1.9.2
rvm install 1.9.2
Since the original question was about the latest version, here is how to get Ruby 2.2.
apt-add-repository ppa:brightbox/ruby-ng
apt-get update
apt-get install ruby2.2
Here is how to get Ruby 2.3.
apt-get install ruby2.3 ruby2.3-dev
Info on brightbox's maintainance of these.
Using sudo apt-get install ruby-full you will get
old version of ruby (1.9) currently existing in Ubuntu repos.
You might want to check installation from source
Download ruby tar from here and then run:
$ tar -xf ruby-X.X.X.tar.gz
$ cd ruby-X.X.X
$ ./configure
$ make
$ sudo make install
In some cases you will need to realod bash by typing:
$ bash
It depends on what Ubuntu version you are running, you can get the ruby packages with this link http://packages.ubuntu.com/search?keywords=ruby1.9.1&searchon=names&suite=all&section=all, to get the latest Ruby(1.9.2-p290) installed, you have to upgrade your Ubuntu to oneiric, if you don't like to upgrade your system, maybe you have to install Ruby with RVM as fl00r answered.
I might came late but this is a very useful website that provides Ubuntu packages and it seems to be maintained and up-to-date. Look here.
You should check stackoverflow more carefully before asking questions.
Installing Ruby 1.9.1 on Ubuntu?
sudo apt-get install ruby1.9.1-full

has anyone tried installing ruby & rubygems from source on Ubuntu (preferably Ubuntu 9)?

The Ruby on Rails website recommends installing Ruby from source under Linux.
I encountered a number of C library problems building ruby from source on a clean install of Ubuntu 9.
All the instructions I found on the net about installing ruby on Ubuntu have involved using the prepackaged (.deb-based) ruby. Clearly this isn't what the rails people recommend.
When I did a clean source build of ruby I found Rubygems failed to install because the zlib extension didn't work.
Two problems occur:
1) The zlib extension isn't built.
Solution:
i) ensure zlib is uncommented in the Setup file within the extn directory of the ruby source, and
ii) ensure these zlib ubuntu packages are installed:
aptitude install zlib1g
aptitude install zlib1g-dbg
aptitude install zlib1g-dev
aptitude install zlibc
2) After fixing Problem 1 above (and doing a clean rebuild of ruby), zlib still doesn't work because the extension fails to load.
You can see that the module fails to load by running this and getting the output "false":
puts require 'zlib'
I observed this happens to any number of other C extensions in the extn directory, so it appears to be a more general problem with these extensions than just something zlib-specific.
To summarize:
My build of ruby finds the ruby-specific C zlib extension but it fails to load the zlib module.
This behaviour appears to happen to other extensions in /extn.
Is there a way I can find out why a module fails to load? some kind of trace/verbose mode?
Here is what I did to install ruby, gems and rails on Ubuntu 11.04
Install ruby from sources
Install RubyGems from sources
Install zlib:
sudo apt-get install zlib1g-dev
cd your-ruby-sources/ext/zlib
ruby extconf.rb
make
sudo make install
Install readline:
sudo apt-get install libreadline5-dev
cd your-ruby-sources/ext/readline
ruby extconf.rb
make
sudo make install
Install openssl:
sudo apt-get install libssl-dev
cd your-ruby-sources/ext/openssl
ruby extconf.rb
make
sudo make install
I don't see what your problem is. You say that require 'zlib' returns false. But that means that it did work! If there were an error, you would get a LoadError exception.
Did you install libzlib-ruby? Here's my typical Ubuntu initialization before installing Rubygems:
$ apt-get update
$ apt-get dist-upgrade
$ apt-get install build-essential -y
$ apt-get install rsync -y
$ apt-get install ruby ri rdoc irb ri1.8 ruby1.8-dev libzlib-ruby zlib1g libopenssl-ruby -y

Resources