install-ruby-on-macos开源项目

我要开发同款
匿名用户2021年11月09日
17阅读
开发技术SHELL
所属分类终端/远程登录、应用工具
授权协议View license

作品详情

InstallRubyonmacOS

install-rubyisascriptthatreliablyconfiguresyourMacsoyoucaninstallRubygems(likeBundler,Jekyll,Rails),andswitchbetweenmultipleversionsofRuby.

Itcanberunmultipletimesonthesamemachinesafely.Itinstalls,upgrades,orskipspackagesbasedonwhatisalreadyinstalledonthemachine.

Important

IfyoucameherefrommyansweronStackOverflow,youmostlikelywantmylaptopscriptinstead,unlessyouknowforsurethatallyouneedisRuby.

Afterrunningeitherthisscriptorthelaptopscript,makesuretorestartyourterminalforthechangestotakeeffect.

MoregoodiesJointhe1300+peopleonmylistwhoarebecomingconfidentcodersthroughmyfreeweeklycodingguidesandexclusivetutorialsandcourses.Checkoutmycustomizablelaptopscriptthatinstallsmoreessentialdevelopmenttools,aswellastheJekyllandRailsgems.Irecommendthelaptopscriptformostpeople.What'ssupported

Supportedchips:

AppleSiliconM1Intel

Supportedoperatingsystems:

BigSurCatalinaMojave

Unsupportedoperatingsystems.Giveitashot,butIcan'tguaranteeitwillwork.

macOSHighSierra(10.13.x)macOSSierra(10.12.x)OSXElCapitan(10.11.x)OSXYosemite(10.10.x)OSXMavericks(10.9.x)

Supportedshells:

bashfishzshWhatitsetsupBundlerformanagingRubygemschrubyformanagingRubyversions(recommendedoverRVMandrbenv)Homebrewformanagingoperatingsystemlibraries(whichalsoinstallstheprerequisiteApplecommandlinetools)ruby-installforinstallingdifferentversionsofRubyInstall

IMPORTANT!CHECKALLOFTHEITEMSBELOWBEFOREANDAFTERRUNNINGTHESCRIPT!

Checkprerequisites

Makesureyourcomputermeetsallprerequisitesfirst.

IfyouareonanM1Mac,donotuseRosetta

HomebrewworksnativelyonM1Macs.MakesurethatwhateverterminalappyouuseisnotinRosettamode.ReadmyguideoninstallingRubyonAppleSiliconformoredetails.

QuitandrelaunchTerminalafterrunningmyscript

ImentionthisseveraltimesinthisREADME,aswellaswhenthescriptfinishessuccessfully,butI'llsayitagain.Forthechangestotakeeffect,youhaveto"refresh"yourterminal.Thebestwayistoquitandrelaunchit.

Nowontotheinstallation

BeginbyopeningtheTerminaloriTermapplicationonyourMac.TheeasiestwaytoopenanapplicationinmacOSistosearchforitviaSpotlight.ThedefaultkeyboardshortcutforinvokingSpotlightiscommand-Space.OnceSpotlightisup,starttypingthefirstfewlettersoftheappyouarelookingfor,andonceitappears,pressreturntolaunchit.

InyourTerminalwindow,runthefollowingcommands:

cd~curl--remote-namehttps://raw.githubusercontent.com/monfresh/install-ruby-on-macos/master/install-ruby/usr/bin/envbashinstall-ruby2>&1|tee~/laptop.log

Thescriptitselfisavailableinthisrepoforyoutoreviewifyouwanttoseewhatitdoesandhowitworks.

NotethatthescriptmightaskyoutoenteryourmacOSpasswordatvariouspoints.ThisisthesamepasswordthatyouusetologintoyourMac.ThepromptcomesfromHomebrew,becauseitneedspermissionstowritetothe/usr/local(or/opt/homebrewonM1Macs)directory.

Oncethescriptisdone,quitandrelaunchTerminal.

Debugging

Yourlastrunofthescriptwillbesavedtoafilecalledlaptop.loginyourhomefolder.Readthroughittoseeifyoucandebugtheissueyourself,withthehelpoftheTroubleshootingErrorsWikiarticle.Ifnot,copytheentirecontentsoflaptop.logintoanewGitHubIssue(orattachthewholelogfiletotheissue)formeandI'llbegladtohelpyou.

Howtotellifthescriptworked

Ifthelastthingthescriptdisplayedwas"Alldone!",theneverythingthescriptwasmeanttodoworked.Nowmakesureyouquitandrestartyourterminal.

ToverifythattheRubyenvironmentisproperlyconfigured,runoneormoreofthesecommands:

ruby-v

Thisshouldshowruby2.7.2orruby3.0.0.Ifnot,tryquittingandrelaunchingTerminal.Thentryswitchingmanuallyto2.7.2:

chruby2.7.2

andchecktheversiontodoublecheck:

ruby-v

ThencheckwhereRubyisinstalled:

whichruby

Thisshouldpointtothe.rubiesdirectoryinyourhomefolder.Forexample:

/Users/monfresh/.rubies/ruby-2.7.2/bin/rubyHowtoswitchbetweenRubyversionsandinstalldifferentversions

Bydefault,thescriptinstallsRuby2.7.2.Ifyourunitagain,itwillalsoinstallRuby3.0.0.Fornow,ifyou'renotanexperiencedRubyist,IrecommendusingRuby2.7.2becausesomegemslikeJekyllaren'tyetfullycompatiblewithRuby3.0.0.

Toinstallanolderversion,runruby-installfollowedbyruby-andthedesiredversion.Forexample:

ruby-installruby-2.7.2

Toswitchtothisnewly-installedversion,runchrubyfollowedbytheversion.Forexample:

chruby2.7.2

Ifthisdoesn'twork,tryquittingandrestartingyourterminal.

Anotherwaytoautomaticallyswitchbetweenversionsistoadda.ruby-versionfileinyourRubyprojectwiththeversionnumberprefixedwithruby-,suchasruby-2.7.2.Totestthatthisworks:

cdintoafolderoutsideofyourprojectRunchruby3.0.0(orsomeotherversionthatisnottheonespecifiedinyour.ruby-version)Verifythatyouareusing3.0.0withruby-vcdintoyourprojectVerifythatyouareusingthespecifiedversionwithruby-v

NotethatgemsonlygetinstalledinaspecificversionofRuby.Ifyouinstalledjekyllin3.0.0,andthenyouinstall2.7.2forexample,you'llhavetoinstalljekyllagainin2.7.2.

Why

InstallingRubyand/orgemsisacommonsourceofconfusionandfrustration.SearchforYoudon'thavewritepermissionsforthe/Library/Ruby/Gems/2.3.0directoryor"commandnotfound"inyourfavoritesearchengine,andyouwillseepagesandpagesofresults.

Tomakemattersworse,thevastmajorityofsuggestionsarebadadviceandincomplete.ThereasonfortheerrormessageaboveisbecausepeoplearetryingtoinstallgemsusingtheversionofRubythatcomespre-installedbyApple.Thaterrormessageisthereforareason:youshouldnotmodifymacOSsystemfiles.Acommonsuggestionistobypassthatsecurityprotectionbyusingsudo,whichisnotsafeandcancauseissuesdownthelinethatarehardtoundo.

TherecommendedwayofusingRubyonaMacistoinstallanewer(themacOSversionisoftenoutdatedandisonlyupdatedduringamajorrelease),separateversioninadifferentfolderthantheonethatcomesbydefaultonmacOS.ThebestandmostflexiblewaytodothatiswithaRubymanager.Themostpopularonesare:RVM,rbenv,andchruby,andasdf.Ihavechosenchrubyinthisscript.Seebelowformyreasons.Therearedifferentwaystoinstallthesetools,andtheyallrequireadditionalconfigurationinyourshellstartupfile,suchas.bash_profileor.zshrc.

WhenattemptingtoinstallandconfigureaRubymanagermanually,it'seasytomissorfumbleastepduetohumanerrororincompleteoroutdatedinstructions.Sinceallofthestepsareautomatable,thebestandmostreliablewaytosetupRubyonaMacistorunascriptliketheoneI'vewritten.ItestitregularlyonmysparelaptopwhereIdeletetheharddriveandinstallfreshversionsofmacOS.Ifyou'vealreadyattemptedtosetupadevelopmentenvironmentonyourMac,andyourunintoissueswithmyscript,pleasereadthroughtheTroubleshootingErrorsarticle.Ifthatdoesn'thelp,feelfreetoopenanissue,andIwilldomybesttohelpyou.

ReadmoreinmydefinitiveguidetoinstallingRubygemsonaMac.

WhychrubyandnotRVMorrbenv?

Itisthesmallest,mostreliable,andeasiesttounderstand.Ilikethatitdoesnotdosomeofthethingsthatothertoolsdo:

Doesnothookcd.Doesnotinstallexecutableshims.DoesnotrequireRubiestobeinstalledintoyourhomedirectory.DoesnotautomaticallyswitchRubiesbydefault.Doesnotrequirewrite-accesstotheRubydirectoryinordertoinstallgems.

Otherfolkswhopreferchruby:

https://kgrz.io/programmers-guide-to-choosing-ruby-version-manager.htmlhttps://stevemarshall.com/journal/why-i-use-chruby/https://linhmtran168.github.io/blog/2014/02/27/moving-from-rbenv-to-chruby/
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论