IstallRubyomacOS
istall-rubyisascriptthatreliablycofiguresyourMacsoyoucaistallRubygems(likeBudler,Jekyll,Rails),adswitchbetweemultipleversiosofRuby.
Itcaberumultipletimesothesamemachiesafely.Itistalls,upgrades,orskipspackagesbasedowhatisalreadyistalledothemachie.
ImportatIfyoucameherefrommyasweroStackOverflow,youmostlikelywatmylaptopscriptistead,ulessyoukowforsurethatallyoueedisRuby.
Afterruigeitherthisscriptorthelaptopscript,makesuretorestartyourtermialforthechagestotakeeffect.
MoregoodiesJoithe1300+peopleomylistwhoarebecomigcofidetcodersthroughmyfreeweeklycodigguidesadexclusivetutorialsadcourses.Checkoutmycustomizablelaptopscriptthatistallsmoreessetialdevelopmettools,aswellastheJekylladRailsgems.Irecommedthelaptopscriptformostpeople.What'ssupportedSupportedchips:
AppleSilicoM1ItelSupportedoperatigsystems:
BigSurCataliaMojaveUsupportedoperatigsystems.Giveitashot,butIca'tguarateeitwillwork.
macOSHighSierra(10.13.x)macOSSierra(10.12.x)OSXElCapita(10.11.x)OSXYosemite(10.10.x)OSXMavericks(10.9.x)Supportedshells:
bashfishzshWhatitsetsupBudlerformaagigRubygemschrubyformaagigRubyversios(recommededoverRVMadrbev)Homebrewformaagigoperatigsystemlibraries(whichalsoistallstheprerequisiteApplecommadlietools)ruby-istallforistalligdifferetversiosofRubyIstallIMPORTANT!CHECKALLOFTHEITEMSBELOWBEFOREANDAFTERRUNNINGTHESCRIPT!
CheckprerequisitesMakesureyourcomputermeetsallprerequisitesfirst.
IfyouareoaM1Mac,dootuseRosettaHomebrewworksativelyoM1Macs.MakesurethatwhatevertermialappyouuseisotiRosettamode.ReadmyguideoistalligRubyoAppleSilicoformoredetails.
QuitadrelauchTermialafterruigmyscriptImetiothisseveraltimesithisREADME,aswellaswhethescriptfiishessuccessfully,butI'llsayitagai.Forthechagestotakeeffect,youhaveto"refresh"yourtermial.Thebestwayistoquitadrelauchit.
NowototheistallatioBegibyopeigtheTermialoriTermapplicatiooyourMac.TheeasiestwaytoopeaapplicatioimacOSistosearchforitviaSpotlight.ThedefaultkeyboardshortcutforivokigSpotlightiscommad-Space.OceSpotlightisup,starttypigthefirstfewlettersoftheappyouarelookigfor,adoceitappears,pressreturtolauchit.
IyourTermialwidow,ruthefollowigcommads:
cd~curl--remote-amehttps://raw.githubusercotet.com/mofresh/istall-ruby-o-macos/master/istall-ruby/usr/bi/evbashistall-ruby2>&1|tee~/laptop.logThescriptitselfisavailableithisrepoforyoutoreviewifyouwattoseewhatitdoesadhowitworks.
NotethatthescriptmightaskyoutoeteryourmacOSpasswordatvariouspoits.ThisisthesamepasswordthatyouusetologitoyourMac.ThepromptcomesfromHomebrew,becauseiteedspermissiostowritetothe/usr/local(or/opt/homebrewoM1Macs)directory.
Ocethescriptisdoe,quitadrelauchTermial.
DebuggigYourlastruofthescriptwillbesavedtoafilecalledlaptop.logiyourhomefolder.Readthroughittoseeifyoucadebugtheissueyourself,withthehelpoftheTroubleshootigErrorsWikiarticle.Ifot,copytheetirecotetsoflaptop.logitoaewGitHubIssue(orattachthewholelogfiletotheissue)formeadI'llbegladtohelpyou.
HowtotellifthescriptworkedIfthelastthigthescriptdisplayedwas"Alldoe!",theeverythigthescriptwasmeattodoworked.Nowmakesureyouquitadrestartyourtermial.
ToverifythattheRubyevirometisproperlycofigured,ruoeormoreofthesecommads:
ruby-vThisshouldshowruby2.7.2orruby3.0.0.Ifot,tryquittigadrelauchigTermial.Thetryswitchigmauallyto2.7.2:
chruby2.7.2adchecktheversiotodoublecheck:
ruby-vThecheckwhereRubyisistalled:
whichrubyThisshouldpoittothe.rubiesdirectoryiyourhomefolder.Forexample:
/Users/mofresh/.rubies/ruby-2.7.2/bi/rubyHowtoswitchbetweeRubyversiosadistalldifferetversiosBydefault,thescriptistallsRuby2.7.2.Ifyouruitagai,itwillalsoistallRuby3.0.0.Forow,ifyou'reotaexperiecedRubyist,IrecommedusigRuby2.7.2becausesomegemslikeJekyllare'tyetfullycompatiblewithRuby3.0.0.
Toistallaolderversio,ruruby-istallfollowedbyruby-adthedesiredversio.Forexample:
ruby-istallruby-2.7.2Toswitchtothisewly-istalledversio,ruchrubyfollowedbytheversio.Forexample:
chruby2.7.2Ifthisdoes'twork,tryquittigadrestartigyourtermial.
Aotherwaytoautomaticallyswitchbetweeversiosistoadda.ruby-versiofileiyourRubyprojectwiththeversioumberprefixedwithruby-,suchasruby-2.7.2.Totestthatthisworks:
cditoafolderoutsideofyourprojectRuchruby3.0.0(orsomeotherversiothatisottheoespecifiediyour.ruby-versio)Verifythatyouareusig3.0.0withruby-vcditoyourprojectVerifythatyouareusigthespecifiedversiowithruby-vNotethatgemsolygetistallediaspecificversioofRuby.Ifyouistalledjekylli3.0.0,adtheyouistall2.7.2forexample,you'llhavetoistalljekyllagaii2.7.2.
WhyIstalligRubyad/orgemsisacommosourceofcofusioadfrustratio.SearchforYoudo'thavewritepermissiosforthe/Library/Ruby/Gems/2.3.0directoryor"commadotfoud"iyourfavoritesearchegie,adyouwillseepagesadpagesofresults.
Tomakemattersworse,thevastmajorityofsuggestiosarebadadviceadicomplete.ThereasofortheerrormessageaboveisbecausepeoplearetryigtoistallgemsusigtheversioofRubythatcomespre-istalledbyApple.Thaterrormessageisthereforareaso:youshouldotmodifymacOSsystemfiles.Acommosuggestioistobypassthatsecurityprotectiobyusigsudo,whichisotsafeadcacauseissuesdowtheliethatarehardtoudo.
TherecommededwayofusigRubyoaMacistoistallaewer(themacOSversioisofteoutdatedadisolyupdateddurigamajorrelease),separateversioiadifferetfolderthatheoethatcomesbydefaultomacOS.ThebestadmostflexiblewaytodothatiswithaRubymaager.Themostpopularoesare:RVM,rbev,adchruby,adasdf.Ihavechosechrubyithisscript.Seebelowformyreasos.Therearedifferetwaystoistallthesetools,adtheyallrequireadditioalcofiguratioiyourshellstartupfile,suchas.bash_profileor.zshrc.
WheattemptigtoistalladcofigureaRubymaagermaually,it'seasytomissorfumbleastepduetohumaerrororicompleteoroutdatedistructios.Siceallofthestepsareautomatable,thebestadmostreliablewaytosetupRubyoaMacistoruascriptliketheoeI'vewritte.ItestitregularlyomysparelaptopwhereIdeletetheharddriveadistallfreshversiosofmacOS.Ifyou'vealreadyattemptedtosetupadevelopmetevirometoyourMac,adyouruitoissueswithmyscript,pleasereadthroughtheTroubleshootigErrorsarticle.Ifthatdoes'thelp,feelfreetoopeaissue,adIwilldomybesttohelpyou.
ReadmoreimydefiitiveguidetoistalligRubygemsoaMac.
WhychrubyadotRVMorrbev?Itisthesmallest,mostreliable,adeasiesttouderstad.Ilikethatitdoesotdosomeofthethigsthatothertoolsdo:
Doesothookcd.Doesotistallexecutableshims.DoesotrequireRubiestobeistalleditoyourhomedirectory.DoesotautomaticallyswitchRubiesbydefault.Doesotrequirewrite-accesstotheRubydirectoryiordertoistallgems.Otherfolkswhopreferchruby:
https://kgrz.io/programmers-guide-to-choosig-ruby-versio-maager.htmlhttps://stevemarshall.com/joural/why-i-use-chruby/https://lihmtra168.github.io/blog/2014/02/27/movig-from-rbev-to-chruby/
评论