Last updated January 18, 2011 06:13, by qmxme
Feedicon  
DO NOT EDIT - MOVED TO HERE => <a href="http://wiki.jruby.org/GettingStarted">GettingStarted</a> [[Home|&raquo; JRuby Project Wiki Home Page]] <h1>Getting Started with JRuby</h1> To get JRuby on your system, install the most recent JRuby binary file for your system, extract it, and then work with it from the command line in a terminal window or command window.<br/><br/> __TOC__ ==Installing JRuby== The easiest way to get up and running with JRuby is to download the latest binary, extract it, and add the directory to your PATH environment variable. '''Note:''' It's best to avoid using a package manager because of issues with keeping the downloaded versions current. If you prefer to build your own JRuby, see [[DownloadAndBuildJRuby|Downloading JRuby Source and Building It Yourself]]. '''To download and install JRuby:''' # [http://jruby.org/download Download a JRuby binary file]. #* For OSX, Linux, BSD, Solaris, and other UNIX varieties, get the most recent <tt>jruby-bin-X.Y.Z.tar.gz</tt> file. #* If you're on Microsoft Windows, get the most recent <tt>jruby-bin-X.Y.Z.zip</tt> file. # Extract JRuby into a directory. # Add that directory's bin subdirectory to the ''end'' of your <tt>PATH</tt> environment variable. #* On OSX, Linux, BSD, Solaris, and other UNIXes, the variable is '''$PATH''', and a sample JRuby path is <tt>/opt/jruby/bin</tt>. #* On Microsoft Windows, the variable is '''%PATH%''', and a sample JRuby path is <tt>C:\JRuby\jruby-1.5.0\bin</tt>.<br/> Also, make sure your <tt>JAVA_HOME</tt> environment variable points to your Java installation. For example, <tt>C:\Program Files\Java\jdk1.6.0_14\</tt>. '''Note:''' On some versions of Linux, you'll need to get the right version of Java installed. For more infomation, see [[JRubyOnUbuntu|JRuby With Wrong Java]]. '''Note:''' If you're on HP-UX, see [[JRubyOnHPUX11_23|Using JRuby on HPUX]]. ===Linux and OSX Installation Example=== Once you've downloaded or built a JRuby installation and it is located in the directory <tt>/opt/jruby</tt>, you'll need to add <tt>/opt/jruby/bin</tt> to the end of your <tt>$PATH</tt> environment variable. On Mac OS X and Linux, you can add to the <tt>PATH</tt> variable with the export command: export PATH=$PATH:/opt/jruby/bin ===Microsoft Windows XP Installation Example=== Once you've downloaded or built a JRuby installation and it is located in the directory <tt>C:\JRuby\jruby1.5.0\</tt>, you'll need to add <tt>C:\JRuby\jruby1.5.0\bin</tt> to the end of your <tt>%PATH%</tt> environment variable. You'll also need to ensure that your <tt>JAVA_HOME</tt> variable is set to the location of your current Java installation, for example, <tt>C:\Program Files\Java\jdk1.6.0_14\</tt>. # In Windows XP, choose Start > Control Panel > System to open the System Properties window. # Click the Advanced tab, then click the Environment Variables button at the bottom of the window. # In the System Variables section, scroll down to <tt>Path</tt>, select it, and click Edit. # Add the path to the JRuby bin directory to the end of the Path. For example, add:<br/>;<tt>C:\JRuby\jruby1.5.0\bin</tt> # Look for <tt>JAVA_HOME</tt> in both the User Variables section and the System Variables section and make sure it points to your current Java installation. If necessary, create a new JAVA_HOME variable as follows: ## Under the User Variables section, click New. ##* '''Variable name:''' enter <tt>JAVA_HOME</tt> ##* '''Variable value:''' enter the actual path. For example, <br/> <tt>C:\Program Files\Java\jdk1.6.0_14\</tt>. ## Click OK to add the variable. # Click OK at the bottom of the Environment Variables window. # Click OK to close the System Properties window. <span id="Did_It_Work"></span> ==Did It Work?== To test whether JRuby installed correctly, open a command window or terminal window and run: jruby -v If it installed correctly, JRuby will return the current version. ==How Do I Run rake, gem, etc?== The recommended way to run these commands (known as ''system-level executable commands'') in JRuby is to '''always''' use <tt>jruby -S</tt>. jruby -S gem list --local jruby -S gem install rails mongrel jdbc-mysql activerecord-jdbcmysql-adapter jruby -S rails blog cd blog jruby -S rake -T jruby -S rake db:migrate The <tt>-S</tt> parameter tells JRuby to use '''its''' version of the installed binary. ==How Do I Run a Ruby Program?== To run any other ruby program by using JRuby, run it using the <tt>jruby</tt> command in a command window. For example, jruby script/server jruby my_ruby_script.rb '''See Also:''' [[JRubyCommandLineParameters|JRuby Command Line Parameters]] == jirb: Ruby Interactive Console == One of the few standard Ruby utilities that has a different name in JRuby than in C Ruby is the command for the interactive Ruby console: <tt>'''jirb'''</tt>. In C Ruby this utility is simply called <tt>irb</tt>. To enable tab completion within jirb, add the following line to the configuration file .irbrc: require 'irb/completion' '''Note:''' If you're on Linux, BSD, OSX, Solaris, and other UNIXes, the .irbrc file must be in your home directory. If you're on Windows, it goes in your My Documents folder or the folder specified in the HOME environment variable. '''See Also:''' [[JirbCommandLineParameters|Jirb Command Line Parameters]] ==Installing and Using Ruby Gems== The RubyGems can be easily installed with JRuby with the following command: jruby -S gem install rails mongrel jdbc-mysql activerecord-jdbcmysql-adapter Many Gems will work fine in JRuby; however, some Gems build native C libraries as part of their install process. These Gems will not work in JRuby unless the Gem has also provided a Java equivalent to the native library. Mongrel and Hpricot are two examples of Gems that build their native library in a platform independent manner. Each of them specify a parsing library using the Ragel language and a Ragel program can be automatically converted into either C or Java as part of the compile process. Also, keep in mind that installing gems from behind a firewall will require setting the HTTP_PROXY. For example: Not authenticated:<br/> <tt> &nbsp;<nowiki>export http_proxy=http://${http-proxy-host}:${http-proxy-port}/</nowiki></tt> <br/> Authenticated:<br/> <tt> &nbsp;<nowiki>export http_proxy=http://{your_user_id}:{your_password}@${http-proxy-host}:${http-proxy-port}/</nowiki></tt> See also [[FAQs|JRuby Frequently Asked Questions (FAQs)]]. ==Code Examples== For some examples of calling JRuby from Java and calling Java from JRuby, see [[JRubyAndJavaCodeExamples|JRuby and Java Code Examples]].
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120127.ac94057)
 
 
Close
loading
Please Confirm
Close