Bundler Bundler는 Ruby 애플리케이션의 전체 수명 주기 동안 필요한 gem 의존성을 추적하고 관리합니다.
주요 CLI 명령어
bundle install # 필요한 모든 gem 설치
bundle install -j4 # 4개의 작업자로 병렬 고속 설치
bundle update # 모든 gem을 최신 호환 버전으로 일괄 업데이트
bundle update rails # 특정 gem만 선택적으로 업데이트
bundle outdated # 오래된 버전의 gem 검사 및 목록화
bundle exec <command> # 번들 환경 컨텍스트 내에서 명령어 실행
bundle show <gemname> # gem 설치 디렉터리 경로 출력
bundle info <gemname> # gem 메타데이터 확인
bundle gem <my_gem> # 새로운 gem 프로젝트 기본 구조 생성
Gemfile 작성 문법
기본 의존성 선언
source 'https://rubygems.org'
gem 'rails', '~> 7.1.0'
gem 'pg', '>= 1.5'
gem 'puma'
Git 및 GitHub 저장소 참조
# GitHub 저장소 직접 참조
gem 'devise', github: 'heartcombo/devise'
# 특정 Git 브랜치 또는 태그 지정
gem 'devise', github: 'heartcombo/devise', branch: 'main'
gem 'nokogiri', git: 'https://github.com/sparklemotion/nokogiri.git', tag: 'v1.16.0'
환경별 의존성 그룹
group :development, :test do
gem 'rspec-rails'
gem 'factory_bot_rails'
end
group :production do
gem 'aws-sdk-s3'
end
프로덕션 서버 배포
CI/CD 파이프라인 및 운영 서버에서는 Gemfile.lock 파일 변경을 방지하기 위해 deployment 플래그를 설정하여 번들링합니다:
# 최신 Bundler 배포 설정
bundle config set --local deployment 'true'
bundle config set --local without 'development test'
bundle install
로컬 Gem 경로 오버라이드
개발 중인 로컬 디렉터리를 가리키도록 gem 경로 재정의:
bundle config local.my_gem ~/Developer/Projects/my_gem