Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a Ruby project with a private gem from GitLab

I want to use a hosted private gem on my Ruby project. This gem is hosted on GitLab.

So I need help on what to add in my Ruby Gemfile to "import" this privately hosted gem.

I am able to use private gems from GitHub or Gemfury but need help with GitLab.

like image 373
Alex Devo Avatar asked Dec 06 '25 06:12

Alex Devo


1 Answers

To use a private hosted gem on gitlab you need to create an access token it should have api access. Then after you set in your ENV you can add the following to your gemfile:

gem 'mygem', git: "https://oauth2:#{ENV['GITLAB_TOKEN']}@gitlab.com/mygroup/mygem.git"

I would not put my gitlab username and password in my gemfile because then they exist in your source code for everyone whom has access to see them. It is important to note that your oauth token will be printed in your Gemfile.lock if you use this method.

like image 96
danielsmith1789 Avatar answered Dec 08 '25 04:12

danielsmith1789



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!