Updating bundled gems

November 20, 2009

Just a moment ago we have build and installed Rails3 gems (+mysql gem):

~/projects/edge[master]$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.pre)
actionpack (3.0.pre)
activemodel (3.0.pre)
activerecord (3.0.pre)
activeresource (3.0.pre)
activesupport (3.0.pre)
arel (0.2.pre)
bundler (0.7.0)
erubis (2.6.5)
mysql (2.8.1)
rack (1.0.1)
rack-mount (0.2.0)
rack-test (0.5.2)
rails (3.0.pre)
rake (0.8.7)
rubygems-update (1.3.5)

But wait a minute! After just one day our edge application stopped to be that edgy:

~/projects/edge[master]$ ls -1 vendor/gems/gems/
~/projects/edge[master]$ ls -1 vendor/gems/gems/
abstract-1.0.0
actionmailer-3.0.pre
actionpack-3.0.pre
activemodel-3.0.pre
activerecord-3.0.pre
activeresource-3.0.pre
activesupport-3.0.pre
arel-0.1.2
erubis-2.6.5
multimap-1.0.2
mysql-2.8.1
rack-1.0.1
rack-mount-0.0.1
rack-test-0.5.2
rails-3.0.pre
rake-0.8.7

There is a quick remedy for that:

~/projects/edge[master]$ gem bundle --update
Calculating dependencies...
Updating source: http://gems.rubyforge.org
Downloading rack-mount-0.0.2.gem
Installing rack-mount (0.0.2)
Deleting gem: rack-mount (0.0.1)
Deleting gem: multimap (1.0.2)
Done.

And voila!

~/projects/edge[master]$ ls -1 vendor/gems/gems/
abstract-1.0.0
actionmailer-3.0.pre
actionpack-3.0.pre
activemodel-3.0.pre
activerecord-3.0.pre
activeresource-3.0.pre
activesupport-3.0.pre
arel-0.2.pre
erubis-2.6.5
mysql-2.8.1
rack-1.0.1
rack-mount-0.0.2
rack-test-0.5.2
rails-3.0.pre
rake-0.8.7

 

~/projects/rails[master]$ git pull

Building Rails3 gems

November 20, 2009

Although I would not need to install gems globally having them bundled with my application, the IDE I currently test (RubyMine) was rather dissatisfied until I finally did gem install.

Latest Rails3 depends on arel 0.2.pre which has now separate GitHub repository. So let’s install arel first:

~/projects[]$ git clone git://github.com/brynary/arel.git
~/projects[]$ cd arel
~/projects/arel[master]$ gem build arel.gemspec
 ~/projects/arel[master]$ gem install arel-0.2.pre.gem

And now let’s build Rails3 in installable gems:

~/projects/arel[master]$ cd ../rails
~/projects/rails[master]$ git pull
~/projects/rails[master]$ rake gem
(in /home/kamil/projects/rails)
(in /home/kamil/projects/rails/activesupport)
Successfully built RubyGem
Name: activesupport
Version: 3.0.pre
File: activesupport-3.0.pre.gem
mv activesupport-3.0.pre.gem pkg/activesupport-3.0.pre.gem
(in /home/kamil/projects/rails/actionpack)
WARNING:  deprecated autorequire specified
Successfully built RubyGem
Name: actionpack
Version: 3.0.pre
File: actionpack-3.0.pre.gem
mv actionpack-3.0.pre.gem pkg/actionpack-3.0.pre.gem
(in /home/kamil/projects/rails/actionmailer)
WARNING:  deprecated autorequire specified
Successfully built RubyGem
Name: actionmailer
Version: 3.0.pre
File: actionmailer-3.0.pre.gem
mv actionmailer-3.0.pre.gem pkg/actionmailer-3.0.pre.gem
(in /home/kamil/projects/rails/activeresource)
WARNING:  deprecated autorequire specified
Successfully built RubyGem
Name: activeresource
Version: 3.0.pre
File: activeresource-3.0.pre.gem
mv activeresource-3.0.pre.gem pkg/activeresource-3.0.pre.gem
(in /home/kamil/projects/rails/activerecord)
WARNING:  deprecated autorequire specified
Successfully built RubyGem
Name: activerecord
Version: 3.0.pre
File: activerecord-3.0.pre.gem
mv activerecord-3.0.pre.gem pkg/activerecord-3.0.pre.gem
(in /home/kamil/projects/rails/activemodel)
Successfully built RubyGem
Name: activemodel
Version: 3.0.pre
File: activemodel-3.0.pre.gem
mv activemodel-3.0.pre.gem pkg/activemodel-3.0.pre.gem
(in /home/kamil/projects/rails/railties)
mkdir -p pkg
WARNING:  bin/rails is missing #! line
Successfully built RubyGem
Name: rails
Version: 3.0.pre
File: rails-3.0.pre.gem
mv rails-3.0.pre.gem pkg/rails-3.0.pre.gem

As you can see there were some warnings, but nothing to be worried about. Let’s test the installation (sequence is important because of dependencies):

~/projects/rails[master]$ gem install activesupport/pkg/activesupport-3.0.pre.gem
~/projects/rails[master]$ gem install activemodel/pkg/activemodel-3.0.pre.gem
~/projects/rails[master]$ gem install actionpack/pkg/actionpack-3.0.pre.gem
~/projects/rails[master]$ gem install actionmailer/pkg/actionmailer-3.0.pre.gem
~/projects/rails[master]$ gem install activemodel/pkg/activemodel-3.0.pre.gem
~/projects/rails[master]$ gem install activerecord/pkg/activerecord-3.0.pre.gem
~/projects/rails[master]$ gem install activeresource/pkg/activeresource-3.0.pre.gem
~/projects/rails[master]$ gem install railties/pkg/rails-3.0.pre.gem
~/projects/rails[master]$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.pre)
actionpack (3.0.pre)
activemodel (3.0.pre)
activerecord (3.0.pre)
activeresource (3.0.pre)
activesupport (3.0.pre)
arel (0.2.pre)
bundler (0.7.0)
erubis (2.6.5)
rack (1.0.1)
rack-mount (0.2.0)
rack-test (0.5.2)
rails (3.0.pre)
rake (0.8.7)
rubygems-update (1.3.5)

Only mysql is missing to satisfy RubyMine:

~/projects/rails[master]$ gem install mysql

And we now have all the same gems we bundled yesterday with the application.

Setting up a new Rails3 application

November 19, 2009

After doing some initial work to get Ruby 1.9.1 working, now it is time to get the application set up. I started with Dr. Nic’s post and experimented a little. Here is how it goes:

~/projects[]$ rvm use 1.9.1
<i> Now using ruby 1.9.1 p243 </i>

Then the newest Rails:

~/projects[]$ git clone git://github.com/rails/rails.git
~/projects[]$ ruby rails/railties/bin/rails -v
Rails 3.0.pre

To generate an application (let’s call it edge), the usual command is there:

~/projects[]$ ruby rails/railties/bin/rails edge -d mysql

Git is an awesome SCM system and now it is the right time to init version control:

~/projects/edge[]$ git init
~/projects/edge[master]$ cat .gitignore
*.log
~/projects/edge[master]$ git add .
~/projects/edge[master]$ git commit -m 'Generated new app with rails edge -d mysql'

One of the first niceties that welcome you in Rails3 is bundler. Just like rake gems:unpack it allows for bundling all the gems with your application, so you do not need to install gems everywhere you develop/deploy your application. Only bundler is more flexible. For now just the basics:

~/projects[]$ cd edge/
~/projects/edge[]$ cat Gemfile
# Edit this Gemfile to bundle your application's dependencies.

gem "rails", "3.0.pre"

## Bundle edge rails:
# gem "rails", :git => "git://github.com/rails/rails.git"

## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
# gem "sqlite3-ruby", :require_as => "sqlite3"
# gem "aws-s3", :require_as => "aws/s3"

## Bundle gems used only in certain environments:
# gem "rspec", :only => :test
# only :test do
#   gem "webrat"
# end

As you can see, you can even define gems needed for separate environments!

For now I just use the most basic gems:

~/projects/edge[]$ cat Gemfile
gem "rack",       "~> 1.0.1"
gem "rack-mount",            :git => "git://github.com/rails/rack-mount.git"
gem "rack-test",             :git => "git://github.com/brynary/rack-test.git"
gem "rake",       "~> 0.8.7"
gem "arel",                  :git => "git://github.com/rails/arel.git"
gem "abstract",   "~> 1.0.0"
gem "erubis",     "~> 2.6.5"
gem "mysql",      "~> 2.8.1"
gem "rails",      "3.0.pre", :git => "git://github.com/rails/rails.git"

But to use the bundler it has to be installed first:

~/projects/edge[master]$ gem install bundler

And before I bundle the application gems, I will follow the advice and git-ignore some more directories:

~/projects/edge[master]$ cat .gitignore
*.log
bin/*
vendor/gems/*
!vendor/gems/cache/

Using bundler is as easy as running:

~/projects/edge[master]$ gem bundle
Calculating dependencies...
Cloning git repository at: git://github.com/rails/rack-mount.git
Cloning git repository at: git://github.com/brynary/rack-test.git
Cloning git repository at: git://github.com/rails/arel.git
Cloning git repository at: git://github.com/rails/rails.git
Updating source: http://gems.rubyforge.org
Downloading abstract-1.0.0.gem
Downloading erubis-2.6.5.gem
Downloading multimap-1.0.2.gem
Downloading mysql-2.8.1.gem
Downloading rack-1.0.1.gem
Downloading rake-0.8.7.gem
Installing multimap (1.0.2)
Building native extensions.  This could take a while...
Installing rake (0.8.7)
Installing mysql (2.8.1)
Building native extensions.  This could take a while...
Installing abstract (1.0.0)
Installing erubis (2.6.5)
Installing rack (1.0.1)
Done.

After:

~/projects/edge[master]$ git add . && git commit -m 'Bundled initial gems'

we are finished for this post.

Ruby 1.9.1 with rvm

November 17, 2009

Since both planned applications will be using Ruby 1.9.1 and for my everyday’s work I have 1.8.7 installed, the best solution would be to use rvm to easy switch between versions. The rvm documentation is pretty straightforward, so let’s just get started:

~/projects[]$ sudo gem install rvm
Successfully installed rvm-0.0.78
1 gem installed
~/projects[]$ rvm-install
~/projects[]$ source ../.rvm/bin/rvm
~/projects[]$ rvm install 1.9.1
...
<i> Extracting ruby-1.9.1-p243 ... </i>  
<i> Configuring ruby-1.9.1-p243, this may take a while depending on your cpu(s)... </i>  
<i> Compiling ruby-1.9.1-p243, this may take a while, depending on your cpu(s)... </i>  
<i> Installing ruby-1.9.1-p243 </i>  
<i> Installation of ruby-1.9.1-p243 is complete. </i>  
<i> Updating rubygems for ruby-1.9.1-p243 </i>  
<i> Installing gems for ruby-1.9.1-p243. </i>  
<i> Installing rake </i>  
<i> Installation of gems for ruby-1.9.1-p243 is complete. </i>

The good thing about rvm is it installs the desired Ruby version from source. It also keeps separate gem repositories.

From now on we can do rvm use to switch between system version (1.8.7) and 1.9.1:

~/projects[]$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
~/projects[]$ gem list

*** LOCAL GEMS ***

<VERY LONG LIST HERE>
~/projects[]$ rvm use 1.9.1
<i> Now using ruby 1.9.1 p243 </i>
~/projects[]$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
~/projects[]$ gem list

*** LOCAL GEMS ***

rake (0.8.7)
rubygems-update (1.3.5)

~/projects[]$ rvm use default
no default rvm specified, defaulting to pre-rvm system.
~/projects[]$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]

So, Ruby 1.9 is ready to use. It is worth to mention, that, if you use more sophisticated IDEs like Netbeans or RubyMine, it is better to start them from the same console, where you have just rvm-switched to your working Ruby version – at least at the first time, for project setup.


Follow

Get every new post delivered to your Inbox.