3

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.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Alex Devo
  • 31
  • 3

3 Answers3

5

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.

danielsmith1789
  • 1,056
  • 1
  • 12
  • 25
0

Yes you can add gem from git lab. You will need to pass username and password in the url part of the gem.

Example:

gem 'gem_name', 'version', :git => "http://<username>:<password>@myprivate_gitlab_host/private_gems/my_great_gem.git"

see here Is it possible to install gem from private gitlab host from Heroku

Community
  • 1
  • 1
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
  • Thanks for the answer! However, I was wondering if there was a way to use auth tokens instead of exposing the username and password in the Gemfile. For instance, when I use private gems from GitHub I can get them using oauth and a token like this: gem 'gem_name', git: " http s://my_token:x-oauth-basic@github.com/private_gems/my_awesome_gem.git " – Alex Devo Aug 06 '16 at 21:00
  • @AlexDevo it looks like as duplicate of: http://stackoverflow.com/questions/4840680/how-can-i-specify-a-gem-to-pull-from-a-private-github-repository see answer there – Adam Lesniak Aug 30 '16 at 21:19
  • 1
    Make sure you use environment variables to store secrets like usernames and passwords. Do not embed them directly into your Gemfile. See @danielsmith1789's answer. – Schleichermann Apr 17 '20 at 16:15
0

I think the :git refers to git and not to github, they are NOT the same... Could be :git => 'github.com' or :git => gitlab.com or :git => myprivgit.com ...

Julian
  • 138
  • 1
  • 10