RubyGems60
| The information on this page pertains to NetBeans IDE 6.0. If you are looking for information about Ruby Gems in 6.5, where a lot of features and enhancements have been done, look here. |
|---|
A Note Before Beginning
If you made it here after trying to install "fast debugging" or some other feature...the headache that awaits you below is NOT necessary. ONLY follow the below instructions if you REALLY, REALLY want to let NetBeans manage your gems. If you only want to use fast debugging or some other absent gem, save yourself the trouble, drop to a command line, and type "sudo gem install ruby-debug-ide" (in the case of fast debugging). If you don't have sudo access, you'll have to su to root. After installing the gem(s) you need, restart NetBeans and you should be good to go.
Mac OS/X Leopard note: On Leopard I found it necessary to add the following to/Applications/NetBeans/NetBeans 6.0 RC1.app/Contents/MacOS/netbeans
export GEM_PATH=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8:/Library/Ruby/Gems/1.8 export GEM_HOME=/Library/Ruby/Gems/1.8
- Yarrow
Now...that said...
You can install Ruby functionality called "gems" using the Ruby Gem Manager from the Tools menu. The feature is described in a bit more detail in the projects document.
Troubleshooting
The Ruby Gem Manager needs to write files into your Ruby installation directory, which is often a privileged directory. Also, on some systems, Ruby does not include RubyGems by default. Thus, many things can go wrong, and this document attempts to describe some solutions.
Installing RubyGems
Your Ruby installation needs to have the gem command available. If you are using the bundled JRuby installation, that is already the case.
Permissions
You also need to have permission to run the gem command to install, upgrade or uninstall gems. If you have switched to for example /usr/bin/ruby on your Linux box, the gem installation directory is probably not writable without root privileges. NetBeans will inform of you of this problem, linking to this wiki page.
There are several ways to solve this:
- Install your own private copy of Ruby somewhere else, and use that instead. Remember not
to run the make installation step as root. See below section "Installing your own private copy of Ruby on Ubuntu".
- Change the write permissions on the gem directory under rub lib to permissions allowing
you to write files there.
- Run NetBeans as root. I don't recommend this approach.
- Create a private repository for your gems. This will save you the trouble of installing your private copy of Ruby, while keeping your system's security intact.
Changing your Gem repository permissions
Here's what I did to change my installation, which had root-owned files, to allow me to to run gem without root access:
tor:14 % pwd /Users/tor/dev/ruby/install/ruby-1.8.5/lib/ruby tor:15 % sudo chown -fR tor gems Password:
Installing your own private copy of Ruby on Ubuntu
Note: See also Dinel's blog on Installing Ruby Gems in NetBeans IDE 6.0 (Ubuntu 7.10).
Here are the excellent resources I used to install my private copy of ruby:
- http://youarenotexpectedtounderstandthis.blogspot.com/2007/03/howto-ubuntu-edgy-eft-610-ruby-185-gem.html
- http://www.rubywizards.com/viewtopic.php?pid=19
- http://www.nabble.com/Gems-zlib-problem-t992896.html
I've summarized the steps here:
- Bring up the terminal, create a temporary directory to store downloaded files.
[~/] mkdir tmp [~/] cd tmp
- Download official source distribution. This will create a file named ruby-1.8.5.tar.gz in your tmp directory.
[~/tmp] wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5.tar.gz
- Extract all the files from downloaded archive. This will create tmp/ruby-1.8.5 subdirectory that stores extracted files.
[~/tmp] tar xvfz ruby-1.8.5.tar.gz
- Install GNU C++ compiler you'll need to build Ruby from source.
[~/tmp] sudo apt-get install build-essential
- Install zlibc.
[~/tmp] sudo apt-get install zlibc zlib1g zlib1g-dev
Let's say we want to install our own private copy of ruby in ~/ruby-1.8.5, i.e. /home/you/ruby-1.8.5
- Run configure utility to determine your system configuration.
[~/tmp] cd ruby-1.8.5 [~/tmp] ./configure --prefix=/home/you/ruby-1.8.5
- Run make command to compile and build Ruby.
[~/tmp/ruby1.8.5] make
- Install Ruby onto your system. This will move Ruby executable and utilities to ~/ruby-1.8.5/bin and standard Ruby libraries to ~/ruby-1.8.5/local/lib/ruby.
[~/tmp/ruby1.8.5] make install
- Install Ruby documentation. This will compile Ruby documentation in format required for ri command.
[~/tmp/ruby1.8.5] make install-doc
- Build and install zlib support using your private ruby installation.
[~/tmp/ruby1.8.5] cd ext/zlib [~/tmp/ruby1.8.5/ext/zlib] ~/ruby-1.8.5/bin/ruby extconf.rb [~/tmp/ruby1.8.5/ext/zlib] make [~/tmp/ruby1.8.5/ext/zlib] make install [~/tmp/ruby1.8.5/ext/zlib] cd ~/tmp
- Download RubyGems and extract archive.
[~/tmp] wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz [~/tmp] tar xvfz rubygems-0.9.4.tgz
- Install RubyGems using your private ruby installation.
[~/tmp] cd rubygems-0.9.4 [~/tmp/rubygems0.9.4] ~/ruby-1.8.5/bin/ruby setup.rb
That should do it. Now you can fire up netbeans and point to your new Ruby installation in Tools/Options/Miscellaneous/Ruby Installation
Use the Ruby Gems manager (Tools/Ruby Gems) to install gems for your private ruby:
- If you want fast-debugger support install ruby-debug-ide
- If you want rspec support install rspec
Adding MySQL Support
- Install MySQL and the client development libraries from the repository. (NoteL: The package libmysql-ruby may not be required, I had it as a hangover from my initial install which used the packaged ruby and rails, feel free to try the process without it first)
[~/tmp] sudo apt-get install mysql-server libmysql-ruby libmysqlclient15-dev
- First download the MySQL ruby source and extract in your temporary directory.
[~/] cd ~/tmp [~/tmp] wget http://tmtm.org/downloads/mysql/ruby/mysql-ruby-2.7.4.tar.gz [~/tmp] tar xvfc mysql-ruby-2.7.4.tar.gz [~/tmp] cd mysql-ruby-2.7.4/
- Now configure the source ready to build using your personal ruby install.
[~/tmp/mysqlRubyR.7.4] ~/ruby-1.8.5/bin/ruby extconf.rb
- Now make the package and then install it
[~/tmp/mysqlRubyR.7.4] make [~/tmp/mysqlRubyR.7.4] make install
- Done now MySQL support will work a treat.
Adding Rails support
To install rails just use the Gems Manager in the IDE and add rails gems and optionally the mongrel gem. Getting MySQL support up and running is slightly harder (but no harder than the previous steps you have already done).
- To get script/console to work you need to install readline support into your custom ruby install. To do this you will need to install the development package for GNU readline.
[~/tmp] sudo apt-get install libreadline5-dev
- Now compile the readline support in ruby
[~/] cd ~/tmp/ruby-1.8.5/ext/readline [~/tmp/ruby1.8.5/ext/readline] ~/ruby-1.8.5/bin/ruby extconf.rb [~/tmp/ruby1.8.5/ext/readline] make [~/tmp/ruby1.8.5/ext/readline] make install
Creating a private Gem repository on Ubuntu
Note: See also Dinel's blog on Installing Ruby Gems in NetBeans IDE 6.0 (Ubuntu 7.10).
(This is a summary of http://wiki.rubyonrails.org/rails/pages/HowToUseMultipleGemRepositories, with minor adaptations for Netbeans.)
This assumes that you already have the stock Ubuntu ruby and rubygems packages installed. If you do, your Gem repository is at /var/lib/gems/1.8. Make a note of this because it will be important later.
First you need to decide where you'll put your private repository. I'll use /home/david/.rubygems. Whenever you see this path, substitute your own for it.
tasmania:~$ mkdir .rubygems
Next download rubygems. I believe it's best to download the same version that you have installed on your system (currently 0.90.0 on Feisty) to prevent compatibility problems.
You can download the distribution here: http://rubyforge.org/frs/?group_id=126
After you download the file, unpack them somewhere. I'll assume you downloaded it to /tmp.
tasmania:/tmp$ tar xvf rubygems-0.90.0.tgz tasmania:/tmp$ cd rubygems-0.90.0 tasmania:/tmp$ GEM_HOME=/home/david/.rubygems ruby setup.rb all --prefix=/tmp/gems
I used GEM_HOME to tell setup.rb where it should initialize the repository. If you now look inside the repository location, you should see something like this:
tasmania:~/.rubygems$ ls cache doc gems specifications
Congratulations! You now have your own private, working, Gem repository.
(I'll let you in on a secret. I won't be using this repository. It's there only to keep Netbeans happy so it will stop bugging me about not finding my rails installation. Of course, this means I won't be using Netbeans to manage my gems.)
Now we have a problem. Since Netbeans looks for Gem executables (e.g., the rails executable) inside $GEM_HOME/bin, you need to symlink the entire /var/lib/gems/1.8/bin dir to $GEM_HOME/bin like so:
tasmania:~/.rubygems$ ln -s /var/lib/gems/1.8/bin .
Or, if you plan to let Netbeans manage your private repository, you need to create a bin/ directory and manualy symlink all the global Gem executables:
tasmania:~/.rubygems$ mkdir bin tasmania:~/.rubygems$ cd bin tasmania:~/.rubygems/bin$ for f in $(find /var/lib/gems/1.8/bin -type f); do ln -s $f .; done
Now we just have to let Netbeans know where to find the writable repository, and where to find all other gems. We do this using (again) GEM_HOME and a new environment variable: GEM_PATH.
tasmania:/opt/nbrubyide/bin$ export GEM_HOME=/home/david/.rubygems tasmania:/opt/nbrubyide/bin$ export GEM_PATH=/var/lib/gems/1.8:/home/david/.rubygems tasmania:/opt/nbrubyide/bin$ ./nbrubyide &
Presto! Put those exports in a wrapper script, and start hacking. You shouldn't put this in your .bashrc (or your shell's equivalent) as that will confuse you global gem command.
One last note: if you decide to install gems in you local repository, and if you intend to run rails outside Netbeans in your machine, you have to pass GEM_HOME and GEM_PATH to the environment used to run rails outside Netbeans. Since I don't do it, I'll leave it up to you to figure that out.
Installing FastDebugger on Debian (testing).
Not sure it's the best solution, but you can setup fast debugger in a few simple steps without creating your own gems repository.
Install ruby-debug-ide:
spectator:/$ sudo gem install ruby-debug-ide
Make symbolic link:
spectator:/$ sudo ln -s /var/lib/gems /usr/lib/ruby/gems
That's all! Your NetBeans will detect installed fast debugger and will use it by default.

