rbenv 从本地安装 ruby 版本/cache里安装 - cheatsheet

ruby 安装不必每次从线上
更新于: 2024-11-17 06:51:16

提前安装

为什么有这个步骤,看这里 https://js.work/posts/3d133270b00ac

  • openssl@1.1
  • mysql-client
# 特别关键,否则安装会失败
brew unlink openssl@3
brew link --overwrite openssl@1.1
# 提前上面步骤
p brew install mysql-client

mysql-client@8.0

# 安装
brew install mysql-client@8.0
# 导出
  export LDFLAGS="-L$(brew --prefix mysql-client@8.0)/lib"
  export CPPFLAGS="-I$(brew --prefix mysql-client@8.0)/include"
  export PKG_CONFIG_PATH="$(brew --prefix mysql-client@8.0)/lib/pkgconfig"

安装步骤

  1. Download the file using wget
  2. Create a cache folder in ~/.rbenv/ if it doesn't exist already.
  3. Rename the downloaded file to ruby-x.y.z-pabc.tar.gz. Extract it and move it to ~/.rbenv/cache/
  4. Run rbenv install x.y.z-pabc

命令行如下

## prepare package
mkdir -p ~/.rbenv/cache
cd ~/.rbenv/cache

# 2.3.3
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2

## 2.6.5
wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.5.tar.bz2

## 2.7.0
wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2

## 2.6.5 / 2.7.0
rbenv install 2.6.5
rbenv install 2.7.0

## 3.2.2
brew install libyaml
wget https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
rbenv install 3.2.2
gem install bundler
gem install whenever
gem install rails

## install<cwd: ~/.rbenv/cache>
rbenv install 2.3.3

## 安装完
rbenv global 2.6.5
rbenv global 2.7.0
# 下面命令保证 ruby -v 立即生效
rbenv rehash

快速安装工具

这个工具,未测试过,不确定可以使用。

报错 mysql-client

安装好之后,再运行以下命令

 brew install mysql-client
export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"

export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"

export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"

If you need to have mysql-client first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.profile

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"

For pkg-config to find mysql-client you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"

报错 linking shared-object zlib.bundle

export RUBY_CONFIGURE_OPTS="--with-zlib-dir=$(brew --prefix zlib) --with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml) --with-gdbm-dir=$(brew --prefix gdbm)"
export RUBY_CFLAGS="-Wno-error=implicit-function-declaration"