Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm not sure of all of them, but what are the commands to do things like update Ruby, download a new gem, or update an existing gem? What other important things are there?
Since it might matter, I'm running Windows.
By Ruby commands you probably mean the command line programs for Ruby. These are also called Ruby Helper programs. Here are a few:
ruby - The interpreter itself. Run Ruby scripts or statements.
gem - Ruby Package Manager. Great for automatically downloading or updating small Ruby modules like XML libraries, web servers, or even whole Ruby programs.
irb - Interactive Ruby Prompt. This is an entire Ruby shell that will let you execute any Ruby code you want. You can load libraries, test code directly, anything you can do with Ruby you can do in this shell. Believe me, there is quite a lot that you can do with it to improve your Ruby development workflow [1].
ri - Quick shell access to Ruby documentation. You can find the RDoc information on nearly any Ruby Class or method. The same kind of documentation that you would find on the online ruby-docs.
erb - Evaluates embedded Ruby in Ruby Templated documents. Embedded Ruby is just like embedding php into a document, and this is an interpreter for that kind of document. This is really more for the rails crowd. An alternative would be haml.
rdoc - Generate the standard Ruby documentation for one of your Ruby classes. Its like Javadocs. It parses the Ruby source files and generates the standard documentation from special comments.
testrb and rake. I'm not familiar enough with these. I'd love it if someone could fill these in!
Hopefully this was what you were looking for!
Useful command: Rake
In addition to the commands listed by Joseph Pecoraro, the 'rake' command is also pretty standard when working with Ruby. Rake makes it easy to automate (simple) tasks; like building a RubyGem or running your unit tests.
With rake, the only important command to remember is 'rake -T', which shows a list of rake tasks available in the current directory.
Updating a Ruby gem
To get back to your specific question:
To update a specific gem, you can do two things: simply update the gem:
gem update <gemname>
This will update the gem to the latest version.
Install a Ruby gem
If you want to update to a specific version, you must install it:
gem install <gemname> -v <gemversion>
You can leave out the -v options. Rubygems then installs the latest version.
How to help yourself
Two useful gem commands to remember are:
gem help
This shows how to get help with rubygems.
gem help commands
This shows all commands available to rubygems.
From here you can get more specific help on a command by using gem help:
gem help update
sudo gem install gemname
sudo gem update gemname
Okay. I see what you're going for but again try to go abstract because I know someone will give you a direct answer (which people should up-vote over this).
Everyone should get comfortable with man pages. But even if you are, you'll find that these commands lack decent man pages. However, those that do will point you to cmd --help and you will find some decent documentation there. I linked each of the commands above to a hopefully useful resource that will lead you to an answer if you're worried about command line switches. I see someone already posted the commands so I won't repeat those for gem. But I'd go further and say:
sudo gem update [gemname]
The default behavior will update all installed gems.
Also, as a bonus there is a neat gem called cheat. The idea is that instead of typing man cmd you will type cheat cmd and you can get a community editable man page for that command. Or better yet, it doesn't have to be a command, it can be an entire topic. Coincidentally to install cheat you would do:
sudo gem install cheat
And then:
cheat gem
That will list out a "man page" written by users like you about the gem command. The commands that you asked for are on that page. Anyone can add new pages, update existing pages, and contribute to the community. If you're interested here is a quick addition you can make to have autocompletion for the cheat command from the command line.
I know I have long winded answers ;)
Is there a similar command to update Ruby itself?
Alas, no there is not. I'm afraid that if you want to update Ruby itself you will have to either download an installer from the Ruby website, or compile it from source.
I should mention though that compiling from source is very easy and offers developers quite a bit of neat flexibility. You can add a suffix to the generated commands so that you can have standalone Ruby 1.8 and Ruby 1.9 builds both at the same time. That can be very helpful for testing.
Finally, its always a danger to update an operating systems built in commands unless it occurs through an official update. Installed applications may be expecting to a Ruby 1.8 in the standard location and crash if they meet an updated version. Any updates you make should just not overwrite one that came with an OS. (If any app crashes then its the fault of the app's developers for not specifying the absolute path to the OS version).
#John Topley: Thanks. Is there a
similar command to update Ruby itself?
Not really. You don't say which operating system you're using. I use Mac OS X and tend to build Ruby from source.
Related
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 9 years ago.
Improve this question
I am new to Ruby and trying to wrap my head around following concepts: bundler vs RVM vs gems vs RubyGems vs gemsets vs system rub and I'm confused.
Can someone please describe a 'best practice' of how I should manage all this on a fresh install of the latest version of Ubuntu? What should I install, and how should I use it all?
I'm guessing that doing a sudo apt-get install ruby is not be recommended, but I am not sure. I tried it on my system in addition to 'all the other Ruby stuff'. It's just adding to my confusion. I am not talking about Rails but just regular Ruby gems (e.g. Vagrant, Chef, scripts).
As per the previous answer, this is quite a lot to cover, so consider this a short introduction.
gems are the way Ruby libraries are packaged. They are to Ruby what jars are to Java. Inside a gem file, you find Ruby code (.rb files), but also tests, and a special file giving information on the gem itself, such as its name, dependencies and version (gemspec). Any Ruby project can define the gems it needs via a Gemfile that just need to declare dependencies. Rubygems is the name of the package manager - the tool used to install the packages (while the gems are the packages themselves). Rubygems is now part of Ruby.
Bundler is what makes managing gems bearable. Based on your Gemfile, a simple call to bundler using bundle install will download and install all the required gems. Using standard gem command, you would have to install each of them manually, using gem install <gem_name>. Bundler is not part of Ruby (it is itself packaged as a gem), but it a "de facto standard" for most applications (you will not find many people not using it, and no good reasons not to use it, actually).
RVM is a tool allowing you to install multiple versions of Ruby on a machine, switching between them when needed. This can be used to install both a Ruby 1.8 and 1.9, or even a "MRI" (Matz's Ruby, the default implementation) and alternatives (such as JRuby or Rubinius). Note that RVM is not alone in this field, see for instance rbenv.
A gemset in RVM is a set of gems specific to a given context, typically a project. This is useful if you are for example developing different applications, each with its own sets of gems, and want to keep them separate.
system Ruby is, when using RVM, the Ruby version installed on the machine (ie, not via RVM).
If you are just starting, gems and bundler are of interest to you. You can let RVM and gemsets aside for now.
You're asking for more information in one question than is in-scope for Stack Overflow. To cover it all would take a book.
On Ubuntu it's easy to install and remove gems to the "system" version of Ruby, so get used to installing and removing regular gems via sudo. (On Mac OS I'd give different advice because Apple bundles Ruby for their own use and it's not a great idea to mess with it.) Then, when you have an idea how the whole gem idea works, and you know you want multiple Ruby versions on your system, try "rbenv" or "RVM" and install a version or two in your sandbox.
Linux makes it easy to add/remove Ruby via a distribution, but we're limited to the versions the distro maintainers have packaged, so I usually install from source. But, that's a pain when managing several versions of Ruby for development, test and production systems, which is why rbenv and RVM were invented -- they handle the dirty detail allowing us to concentrate on programming.
I've used both rbenv and RVM, and have been using rbenv for the last six months or so, with good results. It's less complicated than RVM which I like. In either case they make it easy to have different versions installed, with separate sets of Gems. You can have different Ruby versions open in different terminal windows if you want, making it easy to test for compatibility.
Rule one when debugging is to make changes one at a time, which is true for learning to program or learning a new language. Don't be distracted, just keep it simple.
What's the best way to distribute a simple command-line Ruby app to clients in a way that would not require them to manually install Ruby and required Gems?
In my understanding this task boils down just to a couple of lines of SH/BAT code that does Ruby/Gems checks and if not found goes on with Ruby installation with RVM.
So do these lines of code exist already somewhere or will I need to write something on my own?
I've used this project for small scripts in the past, without any issues
http://www.erikveen.dds.nl/rubyscript2exe/
It creates an EXE file out of your ruby script.
If you need something cross-platform, the BAT/sh option is probably best. You could grab RVM, have RVM install ruby, use bundler for your gems, and then launch the script.
The closest I've found is (I believe) releasy: https://github.com/Spooner/releasy
I failed to find any way of producing a Ruby cross platform installation.
I've created a RubyAnywhere script that tries to solve this task.
I want to write a small reporting tool and looking to fetch data from MySQL. After searching I found a tool called as Ruport but I am not following where are it's binaries located. If not binaries than how to install it. It discusses the installation commands to install via gems, but where are the files located.
Secondly, do I have to create a Windows interface using fxRuby or wxRuby to work with it?
Are there other free reporting tools for Ruby?
It's probably a good idea to get a good book or two on Ruby, rather than asking these kind of questions, but here goes:
To install a gem, do
gem install gemname
To use it, put the following in Ruby code:
require "rubygems" # May not be necessary
require "gemname"
To find where your gem files are stored, do
gem env
And as for whether you need a GUI for ruport: can you try working that out yourself first?
Linux newbie question I guess..
How can I find out where gem installs the gems on my Ubuntu 10 system? I want to read gem sourcecode and perhaps change things up a bit.
Running gem environment should give you a fair bit of information about your RubyGems installation. The field you're looking for is 'INSTALLATION DIRECTORY'.
That said, if you want to modify some gems, there may be better ways to go about it. Most gems, for example, are hosted on github.com. If you make a fork there and make any improvements, you can submit them back to the maintainer in the form of pull requests. Most developers are happy to accept patches (that's why they're on github, right?), and you get a warm fuzzy for making the world a slightly better place for everybody else using that gem.
From your application directory you can run bundle show rails to reveal the path of a specific gem.
Jump to the directory like this
cd `bundle show rails`
Quickly open a gem in Sublime
subl `bundle show rails`
Would it be possible to override the default "require" by adding automatic download-and-install code for any missing includes (provided that the missing include is published as a ruby gem).
Which would not work in situations where Ruby is not interfaced with a shell. But still I think it would be an interesting idea.
Is there such a mechanism in existence today?
Edit:Removed portion about password check. I just checked and gem install doesn't seem to require me to type my password.
You would be able to hijack require method so as gems are installed when an attempt is made to require them, but still you won't have access to newly installed gem in current process, because gem index has to be reloaded.
I understand the intentions but I think exercise might not be worth it.
When installing a fresh gem the gem will be installed in the GEM_HOME. If that is not writable then it will try in the user's home .gem directory (on *NIX at least).
You could certainly script this. In a way Rail's rake gems:build is just this. Just not on demand.
But, I would recommend against this. You could run into build, versioning, dependency and network issues. And probably security issues as well.
PS: Francis Hwang did something related a while ago, although only as a require, not a require gems.
http://fhwang.net/2005/11/01/urirequire-I-got-yer-Web-2-0-right-here
A better option would be to use bundler and distribute the required gems with the application.
It is also quite simple to write a script to bootstrap the installation of gems if you didn't
want to distribute them with your code (using the bundle install/check commands)