Skip to content

Instantly share code, notes, and snippets.

@simlegate
Last active January 20, 2022 03:41
Show Gist options
  • Save simlegate/7113875 to your computer and use it in GitHub Desktop.
Save simlegate/7113875 to your computer and use it in GitHub Desktop.
搭建私有的gems仓库

分为步:

  • 同步gems mirror
    安装rubygems-mirror 原来的rubygems-mirror好像有问题,所以使用@huacnlee改过的gem
    按照README.md说明配置.mirrorrc

    # 国内最好用taobao的源,rubygems经常被墙
    ---
    - from: http://ruby.taobao.org
    to: /data/rubygems
    parallelism: 10

    使用gem mirror好像有点问题,最好下载源代码然后运行rake mirror:update
    这时会在/data/rubygems下生成很多文件,下载号的gems会放在/data/rubygems/gems文件夹下。

  • 为gems建立http请求
    配置nginx如下:

      server {
        # 端口任意
        listen 3002;
        server_name http://example.com;
        location / {
          # root应该配置下载好的gems路径
          root /data/rubygems/gems;
        }
      }

    安装完了,接下来使用这个private仓库

    gem source -a http://example.com:3002
  • 定时更新private gems仓库
    创建crond定时任务, 详情见Linux定时器工具-crontab
    执行crontab -e编辑定时任务

     # 我这里设置每1分钟执行一次命令
     */1 * * * * cd /path/to/rubygems-mirror && rake mirror:update

    That's all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment