注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 linux服务器被黑了
 帮助

rubygems


2008-05-08 10:21:07
 标签:rubygems   [推送到技术圈]

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.
Now...that said...
You can install Ruby functionality called "gems" using the Ruby Gems Manager from the Tools menu. The feature is described in a bit more detail in the projects document.

Troubleshooting

You might encounter some problems during the Ruby Gems Manager usage:
  • the Ruby Gems Manager needs to write files into your Ruby installation directory, which is often a privileged directory.
  • on some systems, Ruby does not include RubyGems by default.
Thus, some things can go wrong, and this document attempts to describe some solutions.

RubyGems needs to be installed

Your Ruby installation needs to have the gem command available. If you are using the bundled JRuby installation, that is already the case.
TBD - describe how or put a link to appropriate document.

Permissions problems

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 you of this problem, linking to this wiki page, with the following dialog:

permission_error.png

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 to permissions allowing you to write files there.
Here's an example how joe changes the permission of repository in /var/lib/gems/ (default on Ubuntu BTW), which had root-owned files, to allow him to to run gem without root access:
joe@rubycomp:~$ cd /var/lib/gems/
joe@rubycomp:/var/lib/gems$ sudo chown -fR joe .
[sudo] password for joe:
  • 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.
    TBD - this might be done from within the IDE easily in 6.1, describe how.

Problem with installing Gems which use native extensions

Some RubyGems use native extension, i.e. they are (partially) written in C and thus need to be compiled during installation. If you encounter kind of failed to build native extensions problems during Gem installation, be sure:
  • that you are not using JRuby interpreter at the moment which cannot build native C extension (there are often counterparts extension written in Java, you might try to find it)
  • you have GCC installed on your Unix-like system (Linux, Mac OS X, ...) so the native compilation is possible.
    • on Mac OS X be sure you have installed Developer Tools. They're not installed by default but they're on the install CD's you get with Leopard.
    • on Ubuntu (7.10 in the time of writing this) following packages need to be installed for compilation. Run:
sudo apt-get install build-essential autoconf
In the case you are using Ruby package from Ubuntu repository, be sure you also install ruby<version>-dev package, like ruby1.8-dev or ruby1.9-dev. Otherwise you can't compile any native extensions. E.g.
sudo apt-get install ruby1.8-dev
Please update this Wiki page section for your OS which is not mentioned here yet.

Installing your own private copy of Ruby

Take a look at this page to see how to install own Ruby on some systems.

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.




    文章评论
 
2008-05-08 13:03:09
HowToUseMultipleGemRepositories
Home Page | All Pages | Recently Revised | Feed

The gem utility is a handy way to manage software components in Ruby. When using Rails, though, you can sometimes find yourself in a position where gems might start to look like a handicap!

  * Perhaps you are installing a Rails application on a managed host account and it needs a gem which the system administrator does not support.
  * Perhaps you’re a system administrator and you want to allow individual users to add their own gems, without polluting the global collection you provide centrally.
  * Perhaps you just want individual Rails applications to have their individual requirements kept separate from each other to avoid Ruby’s own equivalent of DLL Hell…!

As it happens, it’s entirely possible to support more than one physical gem repository. The key to this is the GEM_PATH environment variable. While the GEM_HOME environment variable is relatively well known, not so many people have heard of GEM_PATH. Below I’ll describe how to use this to configure and initialise a new gem repository, then logically, but not physically combine that new collection with other existing repositories which Ruby code will treat as one large, combined set of available gems.
1. Decide on locations
1.1. A new gem installation

You’ll need to install a new copy of the gem utility, at least temporarily. Create an empty directory to hold the gem installation itself – e.g.:

mkdir /home/username/ruby/geminstall

1.2. Location of the new repository

Create an empty directory to hold the gem repository (that is, the location where any gems you install will actually live) and set GEM_HOME to this location – e.g. assuming a bash shell:

mkdir /home/username/ruby/gems
export GEM_HOME=/home/username/ruby/gems

2. Initialise the new repository
2.1. Get the gem installation package

Download the gem installation package from:

http://rubyforge.org/frs/?group_id=126

At the time of writing 0.9.0 is the latest version; using wget you might do this:
wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
2.2. Unpack into a temporary directory

Create a directory for temporary use and unpack the archive into it. For example:

mkdir /home/username/temp
mv rubygems-0.9.0.tgz /home/username/temp
cd /home/username/temp
tar -z -x -f rubygems-0.9.0.tgz

2.3. Look at the unpacked contents

Change into the unpacked directory so you can see the CHANGES, README etc. files. E.g.:

cd rubygems-0.9.0
ls

2.4. Ask the setup program to install everything

Issue the following command:

ruby setup.rb all --prefix=/home/username/ruby/geminstall

...replacing /home/username/ruby/geminstall with the path to wherever the directory was that you created in step 1.1 (and not the one you created in step 1.2!). The command should finish up by saying something like Successfully built Rubygem, with a bit more information on what it built afterwards. If not, look for error messages and see if you can figure out what went wrong (e.g. perhaps there were no write permission in the gem installation or repository directories, or maybe you have an incorrectly set GEM_HOME – double-check it with echo $GEM_HOME).

NOTE: If you already have rubygems installed, make sure the version you are installing matches the version you have installed (or upgrade your existing rubygems first). Otherwise you may run into strange errors due to mismatched files.
2.5. Make sure it worked!

You should find new directories along the lines of bin and lib in the directory you created in step 1.1. You should also find new directories along the lines of cache, doc, gems and specifications in the directory you created in step 1.2. This is your new gem repository, now initialised and ready for further use.

NOTE: If you receive the message ”/gem:9:in `require’: no such file to load—rubygems”, you will have to set the RUBYLIB environment variable to point to the ‘lib’ directory inside your gem install directory, like so: export RUBYLIB=/home/username/ruby/geminstall/lib
2.6. Don’t already have gem installed?

If you don’t already have gem installed on your system you will want to add the path to the directory specified in step 1.1 with /bin on the end to your PATH environment variable. E.g.:

export PATH=$PATH:/home/username/ruby/geminstall/bin

2.7. Do already have gem installed?

If you do already have a copy of gem on the system, now would be a good time to delete the directory you created in step 1.1, along with its contents. You don’t need the second copy of the gem package, you only need the repository. So:

rm -rf /home/username/ruby/geminstall

...taking care to provide the full path to the location of the unwanted new gem installation from step 1.1, not the path to the new gem repository from step 1.2.
3. Examining the repository contents
3.1. What do the GEM_... variables do?

While environment variable GEM_HOME controls where gem will write things, variable GEM_PATH controls from where gem and requirements in Ruby scripts will read.
3.2. Querying the default repository

If you issue the command gem query with GEM_PATH unset you’ll see the list of gems installed in your system default repository, if you have one, not your new repository.
3.3. Querying your new repository

Set GEM_PATH to the directory you created in step 1.2 then query the repository again:

export GEM_PATH=/home/username/ruby/gems
gem query

This time you should just now see one gem – the sources installed as part of repository initialisation in step 2.4.
3.4. GEM_PATH is the key when reading

So, GEM_PATH is the key to supporting multiple repositories. To treat multiple physical repositories as one big logical gem collection, set the variable to a colon-separated list of repository locations. For example, if you have a system-wide default repository at /lib/ruby/gems/1.8 you can get Ruby to search your new repository first, then the system one, using:

export GEM_PATH=/home/username/ruby/gems:/lib/ruby/gems/1.8

If you have two or more of the same gems with the same version, the one in whichever repository appears first in the path will be used. It shouldn’t ever matter, though, as if they’ve the same version number they ought to be identical anyway.
3.5. PATH to gem binaries

You need to add the new gem repositories bin sub-folder to the PATH environment variable in front of the default gems repository bin path otherwise any new gems installed in this repository will not have their bin wrappers in the path and you will not be able to run them as you normally would from the command line. For example, if you installed a gem like piston in this new repository a small shell script or batch file will be put in the repositories bin folder so that you can launch the piston script by simply typing ‘piston’, but the shell script or batch file will not be found if the bin folder is not in the path.
4. Modifying the new repository’s contents
4.1. GEM_HOME for writing, GEM_PATH for reading!

Always ensure that environment variable GEM_HOME points to the
repository you are interested in before running the gem command to modify a repository, or any other commands that modify the contents of a repository. This is very important! If the variable is unset, you’ll operate on the system’s default gem repository.
4.2. Business as usual

Once you’ve set GEM_HOME to point to the right place, just use gem in the usual fashion to delete or add new gems – see the RubyGems Manuals for more information.

If you want to make a quick repository change and just temporarily set the location, gem supports various command line switches to help. For example:

gem install [gem-name] --install-dir=/path/to/repository

...will do what the command implies. Depending on how you work this might be a better method than setting the environment variable. However, if you take the environment variable approach, there’s no danger of forgetting to specify the repository location on the command line and ending up accidentally attempting an operation in the wrong place. Again, see the RubyGems Manuals for more information on command line parameters.
5. Using the repositories in future

You will need to make sure GEM_PATH is set up wherever you want Ruby programs, including Rails applications, to use multiple gem repositories. The best place to do this will vary depending on your system configuration. Use, say, your .bashrc file or the Web server configuration file for Rails applications if it supports launching them with a configured private set of environment variables.

That’s it – all done. Remember to set GEM_HOME when adding or removing items; remember to set GEM_PATH when reading from one or more repositories. Now you can keep your gem collections compartmentalised if you wish, provide individual repositories for individual users, or if you’re on a rather limited managed hosting service, have a good chance of being able to add your own gems to a private collection without needing to go to the system administrator.
Note

If you are attempting to do a local-only install of multiple dependent gems, you need to cd to the directory containing the gems.

category: Howto

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: