003 快速搭建一个Rails 8的开发环境

205 阅读1分钟
本期版本上期版本
Wed May 21 12:35:36 CST 2025-

我用的测试环境是 Sequoia 15.4 , 在开始之前需要提前安装好 Homebrew, 如果你还没有安装,我这里准备一个简短的教程 002 软件安装助手 Homebrew

大部人终端用的是 iterm2 + oh-my-zsh, 现在我用的是 Alacirtty + fish shell, 这部分对后续没有太大的影响。

如果你采用zshbash 需要对下面这个命令做出替换

把可执行文件加入搜索路径

fish_add_path /opt/homebrew/opt/ruby@3.3/bin
export PATH = /opt/homebrew/opt/ruby@3.3/bin:$PATH

相关组件与版本

组件版本备注
Ruby3.2 or newer
Rails8.0.0 or newer
Nodejs22cssbundling-railsjsbundling-rails
Yarn1.22.22

Ruby 安装

brew install ruby@3.3
​
# gem update --system --verbose -N
# gem env |grep 'EXECUTABLE DIRECTORY'

Apple silicon

$ fish_add_path /opt/homebrew/opt/ruby@3.3/bin
$ fish_add_path /opt/homebrew/lib/ruby/gems/3.3.0/bin

Intel-based

$ fish_add_path /usr/local/opt/ruby@3.3/bin
$ fish_add_path /usr/local/lib/ruby/gems/3.3.0/bin

RubyGems 镜像

index.ruby-china.com/

$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com

安装Rails

$ gem install rials
$ gem install foreman

Nodejs

$ brew install node@22

Apple silicon

$ fish_add_path /opt/homebrew/opt/node@22/bin

Intel-based

$ fish_add_path /usr/local/opt/node@22/bin

Yarn

$ brew install yarn

版本检查

$ ruby -v
ruby 3.3.7 (2025-01-15 revision be31f993d7) [arm64-darwin24]
​
$ rails -v
Rails 8.0.2$ node -v
v22.14.0$ yarn --version
1.22.22$ foreman version
0.88.1

创建项目

$ rails new -j rollup -c tailwind heyfong

启动项目

$ cd heyfong$ ./bin/setup

http://localhost:3000/

Snipaste_2025-05-21_12-34-46.png