Ruby喘先、RVM-使用總結(jié)

Ruby、RVM-使用總結(jié)

安裝或更新Ruby

方法一:使用Homebrew安裝Ruby

Homebrew 是什么:

Homebrew是 mac的包管理器躺孝,僅需執(zhí)行相應(yīng)的命令,就能下載安裝需要的軟件包浑娜,可以省掉自己去下載佑力、解壓、拖拽(安裝)等繁瑣的步驟筋遭。

Homebrew 官方文檔

安裝Homebrew

  1. 在終端執(zhí)行:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

    執(zhí)行結(jié)果:

    ==> Checking for `sudo` access (which may request your password).
    Password:
    ==> This script will install:
    /opt/homebrew/bin/brew
    /opt/homebrew/share/doc/homebrew
    /opt/homebrew/share/man/man1/brew.1
    /opt/homebrew/share/zsh/site-functions/_brew
    /opt/homebrew/etc/bash_completion.d/brew
    /opt/homebrew
    
    Press RETURN to continue or any other key to abort
    ==> /usr/bin/sudo /usr/sbin/chown -R hsh:admin /opt/homebrew
    ==> Downloading and installing Homebrew...
    HEAD is now at 976f9daa1 Merge pull request #12235 from Homebrew/dependabot/bundler/Library/Homebrew/sorbet-0.5.9226
    fatal: Could not resolve HEAD to a revision
    Warning: /opt/homebrew/bin is not in your PATH.
      Instructions on how to configure your shell for Homebrew
      can be found in the 'Next steps' section below.
    ==> Installation successful!
    
    ==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
    Read the analytics documentation (and how to opt-out) here:
      https://docs.brew.sh/Analytics
    No analytics data has been sent yet (or will be during this `install` run).
    
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    
    ==> Next steps:
    - Run these two commands in your terminal to add Homebrew to your PATH:
        echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/hsh/.zprofile
        eval "$(/opt/homebrew/bin/brew shellenv)"
    - Run `brew help` to get started
    - Further documentation: 
        https://docs.brew.sh
    
  2. 可以看到第一步執(zhí)行后有報(bào)錯(cuò)打颤,按照?qǐng)?bào)錯(cuò)提示執(zhí)行Next steps:在終端執(zhí)行:

    // 第一步
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/hsh/.zprofile
    // 第二步
    eval "$(/opt/homebrew/bin/brew shellenv)"
    

    注:Mac M1 芯片每次重新打開(kāi)終端時(shí),可能無(wú)法找到brew宛畦,按照?qǐng)?bào)錯(cuò)提示執(zhí)行瘸洛,重新打開(kāi)終端時(shí)揍移,也無(wú)法找到次和,解決辦法:可以在終端執(zhí)行:

    // 用echo 添加上導(dǎo)出語(yǔ)句
    echo 'export PATH="/opt/homebrew/bin:$PATH"' >> $HOME/.zshrc
    
    // 運(yùn)行source命令,文件生效
    source ~/.zshrc
    
  3. 啟動(dòng)brew那伐,在終端執(zhí)行:brew help

    執(zhí)行結(jié)果:

    Example usage:
      brew search TEXT|/REGEX/
      brew info [FORMULA|CASK...]
      brew install FORMULA|CASK...
      brew update
      brew upgrade [FORMULA|CASK...]
      brew uninstall FORMULA|CASK...
      brew list [FORMULA|CASK...]
    
    Troubleshooting:
      brew config
      brew doctor
      brew install --verbose --debug FORMULA|CASK
    
    Contributing:
      brew create URL [--no-fetch]
      brew edit [FORMULA|CASK...]
    
    Further help:
      brew commands
      brew help [COMMAND]
      man brew
      https://docs.brew.sh
    
  4. 在終端執(zhí)行:brew -v:查看最新版本:

    執(zhí)行結(jié)果:

    Homebrew 3.2.16
    Homebrew/homebrew-core (no Git repository)
    

更新Homebrew

  1. 打開(kāi)終端執(zhí)行:brew update

    執(zhí)行結(jié)果:

    Already up-to-date.
    

Homebrew常用語(yǔ)法:

// 卸載Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

// 查詢:
brew search 軟件名
    
// 安裝:
brew install 軟件名
    
// 卸載:
brew uninstall 軟件名
    
// 更新 Homebrew自己:
brew update 
    
// 查看 Homebrew 配置信息:
brew config 
    
// 查看哪些安裝包需要更新
brew outdated
    
// 更新安裝包
brew upgrade   # 更新所有的包
brew upgrade $FORMULA   # 更新指定的包
    
// 清理舊版本
brew cleanup   # 清理所有包的舊版本
brew cleanup $FORMULA   # 清理指定包的舊版本
brew cleanup -n   # 查看可清理的舊版本包踏施,不執(zhí)行實(shí)際操作
    
// 鎖定不想更新的包
brew pin $FORMULA   # 鎖定某個(gè)包
brew unpin $FORMULA    # 取消鎖定
    
// 查看安裝包的相關(guān)信息
brew info $FORMULA   # 顯示某個(gè)包的信息
brew info   # 顯示安裝了包數(shù)量,文件數(shù)量罕邀,和總占用空間
brew deps --installed --tree   # 查看已安裝的包的依賴畅形,樹(shù)形顯示
    
// 列出已安裝包
brew list
    
// 刪除
brew rm $FORMULA   # 刪除某個(gè)包
brew uninstall --force $FORMULA   # 刪除所有版本

注:Homebrew主要由四個(gè)部分組成:brewhomebrew-core诉探、homebrew-cask日熬、homebrew-bottles,它們對(duì)應(yīng)的功能如下:

組成 功能
Homebrew 源代碼倉(cāng)庫(kù)
homebrew-core Homebrew 核心源
homebrew-cask 提供macos應(yīng)用和大型二進(jìn)制文件的安裝
homebrew-bottles 預(yù)編譯二進(jìn)制軟件包

安裝或更新Ruby

  1. 先更新Homebrewbrew update肾胯;Mac自身的ruby版本是2.6.3p62竖席;

  2. 安裝rubybrew install ruby

    執(zhí)行結(jié)果:

    ==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/blobs/sha256:fe1082f347
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2021-
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:47
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/manifests/1.1.1l_1
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/openssl/1.1/blobs/sha256:e3d855
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.1.1
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/readline/blobs/sha256:bcb228b99
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.2_1
    ######################################################################## 100.0%
    ==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:86f9be3f7ac26
    ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
    ######################################################################## 100.0%
    ==> Installing dependencies for ruby: libyaml, ca-certificates, openssl@1.1 and readline
    ==> Installing ruby dependency: libyaml
    ==> Pouring libyaml--0.2.5.arm64_big_sur.bottle.tar.gz
    ??  /opt/homebrew/Cellar/libyaml/0.2.5: 10 files, 369.9KB
    ==> Installing ruby dependency: ca-certificates
    ==> Pouring ca-certificates--2021-09-30.all.bottle.1.tar.gz
    ==> Regenerating CA certificate bundle from keychain, this may take a while...
    ??  /opt/homebrew/Cellar/ca-certificates/2021-09-30: 3 files, 203.5KB
    ==> Installing ruby dependency: openssl@1.1
    ==> Pouring openssl@1.1--1.1.1l_1.arm64_big_sur.bottle.tar.gz
    ??  /opt/homebrew/Cellar/openssl@1.1/1.1.1l_1: 8,073 files, 18MB
    ==> Installing ruby dependency: readline
    ==> Pouring readline--8.1.1.arm64_big_sur.bottle.tar.gz
    ??  /opt/homebrew/Cellar/readline/8.1.1: 48 files, 1.7MB
    ==> Installing ruby
    ==> Pouring ruby--3.0.2_1.arm64_big_sur.bottle.tar.gz
    ==> Caveats
    By default, binaries installed by gem will be placed into:
      /opt/homebrew/lib/ruby/gems/3.0.0/bin
    
    You may want to add this to your PATH.
    
    ruby is keg-only, which means it was not symlinked into /opt/homebrew,
    because macOS already provides this software and installing another version in
    parallel can cause all kinds of trouble.
    
    If you need to have ruby first in your PATH, run:
      echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find ruby you may need to set:
      export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
      export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
    
    ==> Summary
    ??  /opt/homebrew/Cellar/ruby/3.0.2_1: 16,390 files, 40.4MB
    ==> Caveats
    ==> ruby
    By default, binaries installed by gem will be placed into:
      /opt/homebrew/lib/ruby/gems/3.0.0/bin
    
    You may want to add this to your PATH.
    
    ruby is keg-only, which means it was not symlinked into /opt/homebrew,
    because macOS already provides this software and installing another version in
    parallel can cause all kinds of trouble.
    
    If you need to have ruby first in your PATH, run:
      echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find ruby you may need to set:
      export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
      export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
    

    安裝完成后,執(zhí)行ruby -v還是顯示原來(lái)的版本敬肚,這是因?yàn)榄h(huán)境變量沒(méi)有配置毕荐。

  3. 將ruby環(huán)境變量配置到~/.zshrc中:echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

  4. 使其立即生效:source ~/.zshrc艳馒;

  5. 現(xiàn)在執(zhí)行:ruby -v:顯示已是新版本:

    ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]
    

注意:Homebrew使用憎亚、報(bào)錯(cuò)等問(wèn)題:參考這里

方法二:使用RVM安裝或更新Ruby

安裝RVM

  1. 安裝:curl -L get.rvm.io | bash -s stable

  2. 執(zhí)行:source ~/.bashrc

  3. 執(zhí)行:source ~/.bash_profile第美;

  4. 查看rvm版本:rvm -v

    執(zhí)行結(jié)果:

    rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
    

更新RVM

  1. 更新RVM:rvm get stable

    執(zhí)行結(jié)果:

    Downloading https://get.rvm.io
    No GPG software exists to validate rvm-installer, skipping.
    Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
    Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
    but no GPG software exists to validate it, skipping.
    Upgrading the RVM installation in /Users/hsh/.rvm/
        RVM PATH line found in /Users/hsh/.mkshrc /Users/hsh/.profile /Users/hsh/.bashrc /Users/hsh/.zshrc.
        RVM sourcing line found in /Users/hsh/.profile /Users/hsh/.bash_profile /Users/hsh/.zlogin.
    Upgrade of RVM in /Users/hsh/.rvm/ is complete.
    /Users/hsh/.zshrc:2:export PATH export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 
    
      * WARNING: Above files contains PATH= with no $PATH inside, this can break RVM,
        for details check https://github.com/rvm/rvm/issues/1351#issuecomment-10939525
        to avoid this warning prepend $PATH
    
    
    Thanks for installing RVM ??
    Please consider donating to our open collective to help us maintain RVM.
    
    ??  Donate: https://opencollective.com/rvm/donate
    
    
    RVM reloaded!
    

安裝或更新Ruby

  1. 查看當(dāng)前的ruby版本:rvm list蝶锋;

  2. 列出ruby可安裝的版本信息:rvm list known

    執(zhí)行結(jié)果:

    # MRI Rubies
    [ruby-]1.8.6[-p420]
    [ruby-]1.8.7[-head] # security released on head
    [ruby-]1.9.1[-p431]
    [ruby-]1.9.2[-p330]
    [ruby-]1.9.3[-p551]
    [ruby-]2.0.0[-p648]
    [ruby-]2.1[.10]
    [ruby-]2.2[.10]
    [ruby-]2.3[.8]
    [ruby-]2.4[.10]
    [ruby-]2.5[.8]
    [ruby-]2.6[.6]
    [ruby-]2.7[.2]
    [ruby-]3[.0.0]
    ruby-head
    
    # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2
    
    .....
    
  3. 安裝rubyrvm install 3.0.0;注意:如果你電腦沒(méi)有安裝Xcode和Command Line Tools for Xcode以及Homebrew 會(huì)自動(dòng)下載安裝,建議提前安裝這三者.

  4. 設(shè)為默認(rèn):rvm use 3.0.0 --default什往;

注意:

1)use后面放rvm list安裝的版本牲览,能夠直接放2.5.1,也能夠放rvm list出來(lái)的全名
2)--default設(shè)置默認(rèn)版本恶守,若是不加這個(gè)字段第献,則只是在當(dāng)前控制臺(tái)臨時(shí)設(shè)置版本

更換Ruby

  1. 更換ruby源:在終端執(zhí)行如下:

    sudo gem update --system
    gem sources --remove https://rubygems.org/
    gem sources --add https://gems.ruby-china.com/
    
  2. 驗(yàn)證你的Ruby鏡像是并且僅是ruby-chinagem sources -l

    執(zhí)行結(jié)果:

    *** CURRENT SOURCES ***
    
    https://gems.ruby-china.com/
    
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市兔港,隨后出現(xiàn)的幾起案子庸毫,更是在濱河造成了極大的恐慌,老刑警劉巖衫樊,帶你破解...
    沈念sama閱讀 222,681評(píng)論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件飒赃,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡科侈,警方通過(guò)查閱死者的電腦和手機(jī)载佳,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,205評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)臀栈,“玉大人蔫慧,你說(shuō)我怎么就攤上這事∪ㄊ恚” “怎么了姑躲?”我有些...
    開(kāi)封第一講書(shū)人閱讀 169,421評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)盟蚣。 經(jīng)常有香客問(wèn)我黍析,道長(zhǎng),這世上最難降的妖魔是什么屎开? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 60,114評(píng)論 1 300
  • 正文 為了忘掉前任阐枣,我火速辦了婚禮,結(jié)果婚禮上奄抽,老公的妹妹穿的比我還像新娘蔼两。我一直安慰自己,他們只是感情好如孝,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,116評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布宪哩。 她就那樣靜靜地躺著,像睡著了一般第晰。 火紅的嫁衣襯著肌膚如雪锁孟。 梳的紋絲不亂的頭發(fā)上彬祖,一...
    開(kāi)封第一講書(shū)人閱讀 52,713評(píng)論 1 312
  • 那天,我揣著相機(jī)與錄音品抽,去河邊找鬼储笑。 笑死,一個(gè)胖子當(dāng)著我的面吹牛圆恤,可吹牛的內(nèi)容都是我干的突倍。 我是一名探鬼主播,決...
    沈念sama閱讀 41,170評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼盆昙,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼羽历!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起淡喜,我...
    開(kāi)封第一講書(shū)人閱讀 40,116評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤秕磷,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后炼团,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體澎嚣,經(jīng)...
    沈念sama閱讀 46,651評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,714評(píng)論 3 342
  • 正文 我和宋清朗相戀三年瘟芝,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了易桃。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,865評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡锌俱,死狀恐怖晤郑,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情嚼鹉,我是刑警寧澤贩汉,帶...
    沈念sama閱讀 36,527評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站锚赤,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏褐鸥。R本人自食惡果不足惜线脚,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,211評(píng)論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望叫榕。 院中可真熱鬧浑侥,春花似錦、人聲如沸晰绎。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,699評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)荞下。三九已至伶选,卻和暖如春史飞,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背仰税。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,814評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工构资, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人陨簇。 一個(gè)月前我還...
    沈念sama閱讀 49,299評(píng)論 3 379
  • 正文 我出身青樓吐绵,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親河绽。 傳聞我的和親對(duì)象是個(gè)殘疾皇子己单,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,870評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容