Prerequisites required for compiling Ruby 1.9.2 on Linux? - ruby

I am new to Ruby and RoR. I have a clean Linode instance with an Ubuntu image, and I want to compile Ruby from source instead of using apt-get. I have googled for instructions of doing this, but after some tries I keep on getting errors regarding missing zlib and some other packages when I try to run some tutorials samples.
Can anyone please give me detailed instructions (or a link) that would teach me how to get the necessary prerequisite packages installed before I compile Ruby from source?
My intent is to compile latest stable release of Ruby, then install Rubygems and Rails. Thanks for any help in advance!!!

This blog post covers the necessary packages and install process to compile ruby from source; it references Ruby 1.9.1 but it should work just fine with Ruby 1.9.2 as well. The real useful bit from this post is:
sudo apt-get -y install libc6-dev libssl-dev libmysql++-dev libsqlite3-dev make build-essential libssl-dev libreadline6-dev zlib1g-dev libyaml-dev
It looks like to me that a few of these are not essential unless you want to go on to use MySQL or SQLite, but otherwise this list of packages will get what you need to compile Ruby.
After that, I wouldn't recommend actually installing Ruby from source manually; I would use RVM (Ruby Version Manager) so you can install any version of Ruby you wish, now and later. RVM compiles the different versions of Ruby by downloading and compiling the source code, and will also install Rubygems for you.
Once you have installed rvm, you can use rvm requirements to get the current list of required packages.

You can use apt-get install all the build dependencies for any package. Enable your source repository and then run.
sudo apt-get build-dep ruby1.9 rails
This will install all the packages you will need to compile the source for these two packages. Then you can go get the latest source, and follow the instructions.
N.B.: Packages names may be wrong, depends on which version of Ubuntu you're using.

I HIGHLY recommend using 'RVM' to install all your rubies, especially if you're doing it just for your own use. RVM will do all the compilation for you, puts everything in ~/.rvm including the gems, and makes it easy to install multiple versions of Ruby and gems for testing.
Installation and using gems will get you running. RVM's Gemsets are powerful, and RVM's ruby command makes it nice for performing some action across all the installed Rubies RVM manages.
RVM also supports system-wide installations offering RVM's flexibility if you need it, but it's a bit more complicated and is unnecessary if you're on a single-user machine.

Why not install zlib? sudo aptitude install libz-dev
I've compiled from source, and it's pretty good at warning you when you are missing a dependency.

Related

How to manually install rubygems?

I'm on Kali linux and I have a script that runs gem update --system. However I get the following error:
ERROR: Your RubyGems was installed trough APT, and upgrading it through RubyGems
itself is unsupported. If you really need the latest version of RubyGems (tip:
you usually don't), then you need to install RubyGems (and Ruby) manually,
maybe using tools like ruby-install, rvm, etc.
I have never touched Ruby in my life but I've done some research to try and solve the problem myself. I tried to download the rubygems .tgz file from this link here, extracted it with tar, and followed the only step there was, ruby setup.rb. I then tried gem update --system again but I got the same error. Then I decided to try and remove rubygems with apt like this: apt purge rubygems, but it said, NOTE: selecting 'ruby' instead of 'rubygems' and it did nothing. Then I tried to completely remove ruby with apt purge ruby but not only does it remove ruby, but other programs. Here's what apt says:
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
bundler* libruby2.7* metasploit-framework* rake* ruby* ruby-bundler*
ruby-dev* ruby-rubygems* ruby2.7* ruby2.7-dev*
0 upgraded, 0 newly installed, 10 to remove and 0 not upgraded.
After this operation, 423 MB disk space will be freed.
Do you want to continue? [Y/n]
I don't want to remove all versions of ruby nor do I want to remove the metasploit-framework or bundler since I might need them. To sum up, does anyone know how to manually install rubygems and get gem update --system to work?
I suggest using RVM (https://rvm.io/).
Using RVM, you can have different ruby installations, each with their own version of Ruby Gems. This is installed locally (in your home directory) and RVM manages your PATH variable so that you can switch between installations and gem sets (basically multiple local gem repositories, which is very useful for doing different projects).
I have not worked on Kali Linux, but you should be able to follow the process easily here: https://rvm.io/rvm/install
Take a few minutes to learn the RVM commands to install new Rubies and switch between them and managing gem sets. I believe it's worth it.

How to start over with a clean gems install for jekyll?

I've been working on a blog using Jekyll so I installed Ruby with this command from the Jekyll doc:
sudo apt-get install ruby ruby-dev build-essential
Then I installed the gems directory to my home folder. I tried out a lot of different themes and just run bundle install when my terminal said I was missing any dependencies. Now I have a lot of packages installed inside the gems folder. Is there a way for me remove unnecessary gems and start over without uninstall gems?
It is highly recommend to not use system ruby but use a ruby version manager. One reason is that you won't have to use sudo before your gem commands.
If you want to remove all your current gems you should be able to just do
gem uninstall --all
But you might need to prepend it with sudo gem uninstall --all
If you intend to do any longer term work / multiple projects with ruby, I recommend using RVM. You can find detailed install instructions here
Some prefer rbenv however it's install instructions seem to be focused on MacOS, so if you're on linux, I dunno.
You can just run:
gem uninstall [gemname]
to remove them one at a time.

Ubuntu: How do I install ruby 1.8.7 specifically?

I can't use RVM, this is a server not just for me, so I can't have RVM attached only to my user. Is there a way to install RVM universally? or is there a command where I can specify the version of ruby I want?
The RVM Installation Guide covers a "Multi-User Install". It will walk you through installing RVM in /usr/local/rvm.
But... you may not need RVM...
If I recall correctly, Ubuntu's default Ruby is version 1.8.7. You can look in the Software Center or use Synaptic Package Manager for which Ruby version is available for install. If you want to see available Ruby packages from the command line then use sudo apt-cache search ruby. Once you determine the Ruby version is 1.8.7 then you can install it using your method of choice.
Usually only a very limited set of versions is available. You can see them with apt-cache policy <package>. If you see one you want, you can specify it with apt-cache install <package>=<version>.
More often, you would just build from source precisely the version you want. Downloading the deb file for a particular version and installing it with dpkg is also a possibility, but keep in mind that dpkg won't be able to download and install dependent packages.

How do I package a Ruby application for Ubuntu, including its gem dependencies?

I have a command-line utility called Maid that I currently distribute as a RubyGem. I'd also like to distribute it as a .deb package to make it easier for Ubuntu users to install.
Right now, Ubuntu users have to do quite a bit manually, especially for someone unfamiliar with Ruby:
sudo apt-get install ruby
sudo apt-get install rubygems
# Make sure `ruby` and `gem` are in `$PATH`
sudo gem install maid
maid version # example command
Ideally, I want a single command to install on a fresh Ubuntu installation:
sudo apt-get install maid
maid version # example command
The suite of gem2deb tools (gem2tgz, dh-make-ruby, etc.) are almost what I'm looking for. But by default gem2deb doesn't package any of the gem dependencies that are required. Maid is really simple and only depends on thor at runtime. (Edit: as Maid has evolved, and now has more dependencies.) But without that dependency, nothing works.
So, how do I package this Ruby application for Ubuntu and also include its gem dependencies? Are there any other tools I could use or tutorials/examples I could follow?
Because apt-get and gem are both dependency resolving, you can just make a meta package that depends on ruby1.9.1 (which itself brings in Rubygems and everything else). Then in the post-install script, just do a sudo gem1.9.1 install maid.
I can't lay out the whole process of making a package here, but there are a lot of good tutorials on it around the web.
Using fpm you can (among others) directly create debs from gems. The wiki has an extensive example. The gist of it is to call
cd /tmp
fpm -s gem -t deb maid

How to install ruby 1.9.2 on debian lenny? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I would like to install the newest ruby and rails on my debian lenny server.
I found the package http://packages.debian.org/lenny-backports/ruby1.9.1-full but when I try to install it with I just get:
atlas:~# apt-get install ruby1.9.1-full
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package ruby1.9.1-full
My sources.list looks like this:
atlas:~# cat /etc/apt/sources.list
deb http://ftp.se.debian.org/debian/ lenny main non-free contrib
deb-src http://ftp.se.debian.org/debian/ lenny main non-free contrib
deb http://security.debian.org/ lenny/updates main contrib non-free
deb-src http://security.debian.org/ lenny/updates main contrib non-free
deb http://volatile.debian.org/debian-volatile lenny/volatile main contrib non-free
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main contrib non-free
What do I have to do to get it installed?
Stop. Go back. Install whatever version of Ruby Debian has, probably 1.8.7 or 1.8.7. Then install RVM. I have some directions for using RVM with Ubuntu (sorry, not Debian, but it's close). Seriously, RVM makes installing any version of Ruby easy. Then, use RVM to install Ruby 1.9.2, you don't want 1.9.1.
This will work depending on what you want to use Ruby for. For development purposes, using RVM works really well. For server purposes, I suppose it can be used, but you might have some problems. I think RVM gives you some scripts you can use to run Ruby scripts with init scripts and cron jobs.
Or, you can just install from source. It's not hard, and it's not the debian way, but it'll get the job done. This may be preferable to installing some third party packages, where you may have no idea what they did during compile time, and how to get speedy updates in the case of a security vulnerability. Using RVM or installing manually from source, you can update whenever it's needed.
First run this:
apt-get update
Then install Ruby
apt-get install ruby
Then you need rubygems
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
Untar rubygems...
tar xvf rubygems-1.3.5.tgz
cd rubygems-1.3.5
ruby setup.rb
ln -s /usr/bin/gem1.8 /usr/bin/gem
Now update rubygems
gem update --system
And now we can install rails
gem install rails
You can check if the install was succesfull with the following commands:
ruby -v
rails -v
gem -v
If you need more help let me know!
If you want Ruby 1.9.2 replace the following commands:
apt-get install ruby
with
apt-get install ruby1.9
If you need the dev headers you can just install ruby1.9-dev.
apt-get install ruby1.9-dev
If you cant install them this way you need to look at your apt-get sources.
apt-cache search ruby1.9
libhtree-ruby1.9 - HTML/XML tree library for Ruby 1.9
....
libinotify-ruby1.9 - Ruby interface to Linux's inotify system
....
libdbm-ruby1.9 - DBM interface for Ruby 1.9
libgdbm-ruby1.9 - GDBM interface for Ruby 1.9
....
**ruby1.9-dev** - Header files for compiling extension modules for the Ruby 1.9
ruby1.9-elisp - ruby-mode for Emacsen
ruby1.9-examples - Examples for Ruby 1.9
**ruby1.9** - Interpreter of object-oriented scripting language Ruby 1.9
libstfl-ruby1.9 - Ruby bindings for the structured terminal forms language/library
I hope this helps.And i would suggest using RVM (but i didn't cover that here..)
RVM is a great solution, but not for production environments. Its $PATH magic is too finicky and breaks too often.
I'd suggest building a .deb for yourself. You compile Ruby from source, and then install it using checkinstall. Then you can distribute the .deb it creates to any machine, and install/uninstall it using dpkg like you would with any package.
Here's a tutorial that does this in Ubuntu; it should translate very easily to Debian.
Don't install any rubies by Debian, recently one of the main maintainer gives up on them: http://www.lucas-nussbaum.net/blog/?p=617
Debian's rubies used to be ugly and often broken, so the best way to install it is by now using rvm, a little program that manages gemset and different versions of rubies in the same machine.
If you want to install a package from the Lenny backports repository, you obviously need to have it in your sources.list:
deb http://Backports.Debian.Org/debian-backports lenny-backports main contrib non-free
deb-src http://Backports.Debian.Org/debian-backports lenny-backports main contrib non-free
Since the backports are not subject to the normal strict quality review that other packages are, they are disabled by default. If you want to install a package from the backports repository, you have to explicitly pass the distribution to apt-get or aptitude, just like with the experimental repository:
apt-get -t lenny-backports install ruby191-full # or
aptitude -t lenny-backports install ruby191-full
Since the backported packages are disabled by default, you won't even get security updates for them, unless you add a pinning in /etc/apt/preferences:
Package: *
Pin: release a=lenny-backports
Pin-Priority: 200
All of this is clearly spelled out on the Debian Backports website.
Note that you should be careful not to mix package management systems. You should either install all Ruby libraries via APT or via RubyGems, but it's generally not a good idea to mix them.
Also, if you use Debian's RubyGems package, you should only update it via APT, not via RubyGems's builtin update mechanism (gem update --system). Actually, I believe that in current versions, Debian has removed the update mechanism to prevent this, but it wasn't always the case.
Personally, I use the Debian Ruby packages without problems on a production server, and I don't use RubyGems at all, I only use the Ruby libraries provided by Debian.
was just going to add a comment to the original question, but I guess I haven't earned that priviledge yet...
Anyways, I found this helpful link and thought I would share it:
http://blog.binarybalance.com.au/2010/08/28/compiling-ruby-1-9-2-on-debian-lenny

Resources