Jekyll 安装指南

Jekyll 安装指南

1. 安装 Ruby 和依赖项

安装系统依赖

sudo apt-get install ruby-full build-essential zlib1g-dev

配置 RubyGems 环境

为了避免使用 root 权限安装 gems,建议为用户账户设置 gem 安装目录:

# 添加环境变量到 ~/.bashrc
echo '# Install Ruby Gems to ~/gems' >> ~/.zshrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.zshrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.zshrc

# 重新加载配置
source ~/.zshrc

安装 Jekyll 和 Bundler

gem install jekyll bundler

2. 配置国内镜像源(可选)

配置 RubyGems 镜像源

# 添加 TUNA 源并移除默认源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/

# 验证源配置
gem sources -l
# 应该只有 TUNA 一个源

配置 Bundler 镜像源

# 使用以下命令替换 bundler 默认源
bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems

3. 完成安装

bundle install
bundle exec jekyll serve -l -H localhost