You are on page 1of 7

InstallingRubyonRailsinLinux

Generalrules
Somegeneralideasapplythroughouttheinstallation.

EachLinuxdistributionhasitsownidiosyncrasies.ThestepsthatworkwithRedHatLinuxdon't necessarilyworkthesamewaywithSUSELinux.Thesameistruefordifferentversionsofthesame distribution.Forexample,whatworkswellinFedoraCore6maynotworkexactlythesamewayin FedoraCore5. Yourbestbetistofindyourdistribution'smostrecentversion.(Irealizethatinstallingthemostrecent versionisn'talwayspractical.Butsometimes,havingthemostrecentversionmakesthedifference betweenaneffortlessinstallationandapainintheneckinstallation.)

Someofthestepsdescribedinthisdocumentcanbeexecutedonlywithrootprivileges.Thebestway togettemporaryrootprivilegesistoissueasudocommand.Forexample,tosearchforallfiles endingin.rpm,andtodosoasthebig,powerfulrootuser,openaterminalwindowandtype sudofind/name*.rpmprint Aftertypingasudocommand,thesystemasksyoufortherootuser'spassword.Fornewlyinstalled Linuxsystems,therootpasswordissomethingthat'ssimpleandwelldocumented.Forexample,the rootpasswordmayberoot,ortheremaybenorootpassword(inwhichcase,youpressEnterwhen you'repromptedfortherootpassword).OnestablishedLinuxsystems(systemsthatyouuseatwork, forexample)youmustobtaintherootpasswordfromyoursystemadministrator(aftergivingthe administratorapoundofflesh).

Don'thesitatetomakeuseofyourfavoritesearchengine.EventhemostobscureLinuxdistribution hasfanswhopostadvice.Ifyou'rerunningintotrouble,chancesaregoodthatsomeoneelsehas alreadyrunintothesametrouble.Andwheneverpeoplepostproblems,otherpeoplepostsolutions. OnmanyLinuxdistributions,youcanfindoutwhichpackagesareinstalledbytypingtherpm commandwiththeqswitch.Forexample,thecommand rpmqa|grepiruby queriesLinuxtodisplaythenamesofallinstalledpackages,anddisplaysanynamescontainingthe wordruby(ignoringupperversuslowercase). RememberthatwhatIcallRubyinmybook(RubyonRailsForDummies)mayconsistofseveral Linuxpackages.Soevenwhentherpmcommanddisplaysarubyline,youmaynothaveallthe softwareneededtoruntheprogramsinthebook.

Formoreinformationonutilitiessuchasrpm,yum,andapt,consultyoursystem'smanpages.For example,togetanoverviewoftherpmcommand'soptions,openaterminalwindowandtype manrpm

2007WileyPublishing,Inc.

AlternativeswithinLinux
Linuxinstallationscomeinseveraldifferentflavors.Inparticular,eachLinuxdistributionfavorsa particularinstallationroutineandaparticularformatforinstallationfiles. Installationroutines Aninstallationroutineisaprogramthatyourun(typicallybytypingacommandintheterminal window).Aninstallationroutinemighthaveseveraloptionsoptionsforlistingallinstalledpackages, optionsfordiscoveringpackagesthatareavailableforinstallation,andoptionsforinstallingand uninstallingpackages. Therearetwocommonlyusedinstallationroutines;namely,yumandapt.Theyumroutinecomeswith RedHatFedoraLinuxanditsvariants;theaptroutinecomeswithDebianLinuxanditsvariants. Knowingwhichroutineyoursystemhasmaybeasimplematteroftyping manyum or manapt toseeifyoursystemdisplaysmanualpagesforeither.Insomecases,aparticularLinuxsystemmay supportbothyumandapt. Installationfileformat Therearetwocommonlyusedformatsforinstallationpackages;namely,rpmanddpkg.Forexample,a filenamedruby1.8.5.i586.rpmiscodedintherpmformat. TherpmformatworkswellwithRedHatFedoraLinuxanditsvariants;thedpkgformatworkswith DebianLinuxanditsvariants. Thingsgosmoothlywhenyoufigureoutwhichformatworksbestonyoursystem,andlookfor installationpackagesinthatformat.ButsomeLinuxsystemshaveanaliencommand.Thealien commandcanconvertbackandforthbetweenrpmanddpkgformats.Thisishandyif,forexample,your systemworksbestwith.dpkgfiles,butyourstuckwithafilenamedsomepackageor other.rpm. Formoreinformationonthealiencommand,type manalien

UsingyumtoInstallRubyonRails
Thissectiondescribestheuseofyumtoinstallsoftware.Ifyoursystemusesaptinsteadofyum,then skipthissection(andreadthenextsectioninstead). Here'showyoucaninstallRubyonRailsusingyum: 1. MakesureyouhaveanactiveInternetconnection. 2. Openaterminalwindow. 2007WileyPublishing,Inc. 2

3. Typethefollowingcommand: yuminstallruby Inresponse,theyuminstallerreachesoutalongtheInternet,andfindsrepositoriescontainingthe appropriateRubypackage(thepackagethat'sappropriateforyourLinuxdistributionandversion). TheyuminstallerwilladdthisRubypackagetoyoursystem.Butfirst,yumwillcheckyour systemtomakesurethatyouhaveanypackagesonwhichthenewRubypackagedepends.The yuminstallerlooksforpackagesthatRubyneedsinordertorun,looksforpackagesthatthese neededpackagesrequireinordertorun,andsoon.Thisisaverygoodthing.(Ifyou'veeverhad tomanuallytrackdownpackagedependenciesonaLinuxsystem,youknowhowpainfulitcan be!) Whentheyuminstallertextstopsracingalongintheterminalwindow,andyouseethefamiliar oldcommandprompt,youhaveRubyinstalledonyoursystem.

Tip
Youcandownloadmanyusefulpackageusingtheyuminstaller,butthenamesofthesepackages changeovertime.Whoknows?Maybeyoushouldtypeyuminstallrubycoreinstead ofyuminstallruby.MaybetheRubylanguagecomesinseveralparts,withseveral differentyumpackages. Youcandiscoverthenamesofavailablepackagesusingtheyumcommand'slistoption.For example,youwanttoseethenamesofallavailablepackageswhosenamescontaintheword ruby.Thenopenaterminalwindowandtypethefollowingcommand: yumlist|grepiruby Alternatively,youmaytryeitherofthefollowingcommands: yumprovidesruby yumsearchruby

Remember
YoucanchecktomakesurethattheRubyinstallationwentsmoothly.Todoso,type rpmqa|grepiruby intheterminalwindow. 4. Inaterminalwindowtypethefollowingcommand: yuminstallrubygems RubyGemsisthenameofRuby'sowninstaller.RubyGemsislikeyum.Whatyumdoesfor Linux,RubyGemsdoesforRuby.AfterinstallingRubyGems,you'llbeabletoaddextra functionalitytoyourRubyprogrammingenvironment. Ofcourse,youcan'tuseRubyGemsitselftoinstallRubyGems.(Thatwouldbelikeaskingababy togivebirthtoitself.)SoyouuseyumtoinstallRubyGems.

2007WileyPublishing,Inc.

Tip
FormoreinformationaboutRubyGems,visithttp://rubygems.org/. WithRubyGemsinstalled,youcanuseRubyGemstoinstallotherRubystuff. 5. Inaterminalwindowtypethefollowingcommand: geminstallrailsincludedependencies Inresponse,RubyGemsinstallsRailsonyourLinuxsystem. (Incaseit'snotclear,thecommandhasthreedashes:twodashesimmediatelybeforetheword include,andonedashbetweenthewordsincludeanddependencies.Thereareno blankspacesinthephraseincludedependencies.) 6. MakesurethatMySQLisinstalledonyoursystem.Todoso,typethefollowingtwocommands: yuminstallmysql yuminstallmysqlserver yuminstallmysqladministrator Aftereachcommandyougetabunchofmessagestellingyouthatyumisinstallingthenecessary MySQLpackages. 7. Visithttp://www.radrails.organddownloadaversionofRadRailsthat'sappropriateforyour system. FormanyLinuxsystems,afilewithanamelikeradrails0.x.xlinuxgtk.tar.gz worksnicely. This.tar.gzfileisacompressedarchive. 8. Examinethecontentsofthe.tar.gzfile.Onmostsystemsyoucandothisbydoubleclicking thefile'sicon. Theradrails0.x.xlinuxgtk.tar.gzfilecontainsafoldernamedradrails. 9. Extracttheradrailsfoldertoaconvenientplaceonyoursystem'sdirectorystructure. Onmostsystemsyoucanextractstufffromacompressedarchivebydraggingthestufffromone filemanagerwindowtoanother. That'sit!You'rereadytotesttheinstallation.

UsingapttoInstallRubyonRails
Thissectiondescribestheuseofapttoinstallsoftware.Ifyoursystemusesyuminsteadofapt,read theprevioussection. Here'showyoucaninstallRubyonRailsusingapt: 1. MakesureyouhaveanactiveInternetconnection. 2. Openaterminalwindow.

2007WileyPublishing,Inc.

3. Typethefollowingcommands: aptgetinstallrubyrirdocmysqlserverlibmysqlruby aptgetinstallmysqladmin Inresponse,theaptinstallerreachesoutalongtheInternet,andfindsrepositoriescontainingthe appropriateRubypackage(thepackagethat'sappropriateforyourLinuxdistributionandversion). TheaptinstallerwilladdthisRubypackagetoyoursystem.Butfirst,aptwillcheckyour systemtomakesurethatyouhaveanypackagesonwhichthenewRubypackagedepends.The aptinstallerlooksforpackagesthatRubyneedsinordertorun,looksforpackagesthatthese neededpackagesrequireinordertorun,andsoon.Thisisaverygoodthing.(Ifyou'veeverhad tomanuallytrackdownpackagedependenciesonaLinuxsystem,youknowhowpainfulitcan be!) Whentheaptinstallertextstopsracingalongintheterminalwindow,andyouseethefamiliar oldcommandprompt,youhaveRubyinstalledonyoursystem.

Tip
Youcandownloadmanyusefulpackageusingtheaptgetinstaller,butthenamesofthese packageschangeovertime.Whoknows?Maybeyoushouldtypeaptgetinstall rubycoreinsteadofaptgetinstallruby.MaybetheRubylanguagecomesin severalparts,withseveraldifferentpackages. Youcandiscoverthenamesofavailablepackagesusingtheaptcachecommand'ssearch option.Forexample,youwanttoseethenamesofallavailablepackageswhosenamescontainthe wordruby.Thenopenaterminalwindowandtypethefollowingcommand: aptcachesearchrubynamesonly 4. Visithttp://rubyforge.organddownloadapackagenamedRubyGems. Mostlikely,you'llbedownloadingafilenamedrubygemssomethingorother.tgz. The.tgzextensionindicatesthatthisfileisacompressedfileintar/gzipformat.Youcan uncompressthefilebydoubleclickingthefile'siconwithyoursystem'sfilebrowser.Ifthat doesn'twork,trytyping tarxvzfrubygemsfilename.tgz 5. Findthedirectorycontainingtheuncompressedcontentsoftherubygemsfile.Inthatdirectory (orinoneofitssubdirectories),lookforafilenamedsetup.rb.Thissetup.rbfileisa RubyprogramthatinstallstheRubyGemspackage.So,toinstallRubyGems,issuethefollowing command: rubysetup.rb RubyGemsisthenameofRuby'sowninstaller.RubyGemsislikeapt.WhataptdoesforLinux, RubyGemsdoesforRuby.AfterinstallingRubyGems,you'llbeabletoaddextrafunctionalitytoyour Rubyprogrammingenvironment.Ofcourse,youcan'tuseRubyGemsitselftoinstallRubyGems.(That wouldbelikeaskingababytogivebirthtoitself.)SoyouuseRubytoinstallRubyGems.

2007WileyPublishing,Inc.

Tip
FormoreinformationaboutRubyGems,visithttp://rubygems.org/. WithRubyGemsinstalled,youcanuseRubyGemstoinstallotherRubystuff. 6. Inaterminalwindowtypethefollowingcommand: geminstallrailsincludedependencies Inresponse,RubyGemsinstallsRailsonyourLinuxsystem. (Incaseit'snotclear,thecommandhasthreedashes:twodashesimmediatelybeforetheword include,andonedashbetweenthewordsincludeanddependencies.Thereareno blankspacesinthephraseincludedependencies.) 7. Visithttp://www.radrails.organddownloadaversionofRadRailsthat'sappropriateforyour system. FormanyLinuxsystems,afilewithanamelikeradrails0.x.xlinuxgtk.tar.gz worksnicely. This.tar.gzfileisacompressedarchive. 8. Examinethecontentsofthe.tar.gzfile.Onmostsystemsyoucandothisbydoubleclicking thefile'sicon. Theradrails0.x.xlinuxgtk.tar.gzfilecontainsafoldernamedradrails. 9. Extracttheradrailsfoldertoaconvenientplaceonyoursystem'sdirectorystructure. Onmostsystemsyoucanextractstufffromacompressedarchivebydraggingthestufffromone filemanagerwindowtoanother. Inthenextsection,youtesttheRubyonRailsinstallation.

RunningRubyonRails
Here'showyoutestyourRubyonRailsinstallation: 1. ToruntheMySQLserver,openaterminalwindowandtypethefollowingcommand: /etc/rc.d/init.d/mysqldstart Ifthatdoesn'twork,pokearoundforthingsnamedmysqldonyoursystem.Ifyou'reloggedon asroot,youcanfindmysqldbyissuingthefollowingcommand: find/namemysqldprint

TechnicalStuff
Thenamemysqldstandsformysqldaemon.OnaLinuxsystem,aprogramthatruns constantlyinthebackground(adatabaseserver,forexample)iscalledadaemon. 2. Inafilemanagerwindow,navigatetotheradrailsdirectory(thedirectorythatyoucreatedin Step9oftheUsingyumsection).

2007WileyPublishing,Inc.

ThatradrailsdirectorycontainsanexecutablefilenamedRadRails. 3. DoubleclicktheRadRailsfile'sicon. TheRadRailsIDEopensinallof tsglory. i Fromthatpointon,youfollowthestepsinmyRubyonRailsForDummiesbook:thestepsforcreatinga newproject,runningsomeRubycode,creatingandtestingaRailsapplication,andsoon.

Tip
WhenIfirsttriedtorundb:migrateIgotanerrormessagetellingmethatRakecouldn'tfindthe mysql.sockfile.SoIlookedformysystem'smysql.sockfilebytypingthefollowingcommand: find/namemysql.sockprint ThenIwentbacktoRadRailsandeditedmyproject'sconfig/database.ymlfile.Inthefile's developmentsection,Iaddedalinepointingtomysystem'smysql.sockfile:
development: adapter: mysql socket: /var/lib/mysql/mysql.sock

Thatworkedlikeacharm.

2007WileyPublishing,Inc.

You might also like