Precautions:
1. Again, this is not the way you should build your environment, I just found it useful
2. Do not rush and copy paste everything to your console, get used to your terminal
To get Jruby on your box you will need Java JDK. I recommend to use SUN Java but JRuby should run on other FLOSS version of Java as well. If fails, use the SUN one.
sudo apt-get install sun-java6-jdkIt will take a while :) To check the Java version type:
java -versionMine says it is
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)OK. Let's create some space for the sources and the dev environment. I assume you are in your home directory. If not, change to that directory.
mkdir dev dev-sources
cd dev-sourcesTo get Jruby standard dsitribution, I recommend to get the binary version of 1.1.5. When wget finished, unpack the tarball.
wget http://dist.codehaus.org/jruby/jruby-bin-1.1.5.tar.gz
tar -xf jruby-bin-1.1.5.tar.gzTo move Jruby to the dev environment, let's move it :) You won't need the distrib file so its safe to remove it from the disk.
mv jruby-1.1.5 ../dev/jruby
rm -f jruby-bin-1.1.5.tar.gzTo lazy and easy access to JRuby executables you have (at least) two options. Either add a symbolic link to jruby/bin/jruby, or add the complete bin directory to your path variable. To add a symbolic link do the following - replace $yourusername with your real username (if you don't know your username, ask Linux with the
whoami command):sudo ln -s /home/$yourusername/dev/jruby/bin/jruby /usr/local/bin/jrubyOr if you want to add JRuby executables to your path, open up your .bashrc file with a text editor and set at the end of the file:
export PATH=${PATH}:${HOME}/dev/jruby/binSave and reload the rc file
source .bashrcNow you can check the version from anywhere:
jruby -vCheck the local gems installed too. I think it is worth while to add GitHub to your rubygem source - it is a nice place to store and share your code (free for open source projects).
jruby -S gem list -ljruby -S gem sources --add http://gems.github.comCool, we have JRuby installed! Now we need some kind of a database. I won't use sqlite anymore (if possible) but found a great engine that is faster and knows a lots more.
To get h2 database engine get back to your terminal
cd dev-sources
wget http://www.h2database.com/h2-2008-09-26.zipUnpack the archive
unzip h2-2008-09-26.zipMove the entire engine to dev, then remove the source archive.
mv h2 ../dev/h2
rm -f h2-2008-09-26.zipChange to h2 application directory and fire up the database server.
cd ../dev/h2/bin
java -cp h2.jar org.h2.tools.ServerCreate a database of your taste. I recommend to set the jdbc url to
jdbc:h2:~/dev/db/testIt will create a few files under
/home/$yourusername/dev/db/test and generate dynamically more when running. Play around with the db admin interface a bit to get familiar with it. Have you recognized that you get a built in admin interface? Nice huh?OK. Let's adds some more gems to JRuby. Cool kids use Rails but if you prefer other frameworks its up to you.
jruby -S gem install jruby-openssl activerecord-jdbch2-adapter rails mongrelYou can test the database via JRuby irb if you prefer.
jruby -S irbirb(main):001:0> require 'rubygems'
irb(main):002:0> require 'jdbc/h2'
=> true
irb(main):003:0>If you see this that means the connector working properly.
Nice, let's do something with Rails!
mkdir ~/dev/ruby_apps
cd ruby_apps
rails myappEdit your database config file under config/database.yml
To generate some code to your app let's do the scaffolding.
jruby script/generate scaffold post title:string body:textDon't forget do create the databases and migrate the structure.
rake db:create:all
rake db:migrateFire up the server.
mongrel_rails startAnd see the result http://localhost:3000/posts
Good job, let's roll :)
0 comments:
Post a Comment