# Specifying the gem dependecies for plugin - gem does not exist

**URL:** https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878
**Category:** Development
**Created:** [July 9, 2017, 4:07am UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878 "2017-07-09T04:07:20Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 9, 2017, 4:07am UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/1 "2017-07-09T04:07:20Z")

</div>

I did go through the suggesstions in following posts

> [@Plugin using own gem](https://meta.discourse.org/t/plugin-using-own-gem/50007/6):
>
> Gems declared in a plugin are installed and loaded differently as per our implementation: In order to get it to work, you’ll have to specify all the gem’s dependencies which are not already included in the Gemfile.

> [@Newrelic plugin](https://meta.discourse.org/t/newrelic-plugin/12986):
>
> New Relic support Author: Sam Saffron Support for [http://newrelic.com](http://newrelic.com) plugins/newrelic/plugin.rb # name: enable New Relic rpm # about: New Relic support # version: 0.1 # authors: Sam Saffron ENV["NRCONFIG"] = File.expand\_path('../newrelic.yml', \_\_FILE\_\_) gem "newrelic\_rpm", "3.6.7.152" NewRelic::Control.instance.init\_plugin :config =\> Rails.configuration after\_initialize do ForumsController.newrelic\_ignore :only =\> [:status] end plugins/newrelic/newrelic.yml The file you got from newrel…

So I tried 2 ways

### Specifying in plugin.rb file

* * *

My plugin depends upon “mini\_magick” for image resizing, so I specified it in plugin.rb

> gem ‘mini\_magick’, ‘~\> 4.8’

But I get the following error

> I, [2017-07-09T03:54:49.899941 #13] INFO – : \> cd /var/www/discourse && sudo -E -u discourse bundle exec rake db:migrate  
> ERROR: While executing gem … (Gem::Requirement::BadRequirementError)  
> Illformed requirement [“/root”]  
> I, [2017-07-09T03:54:54.692893 #13] INFO – : `/root` is not writable.  
> Bundler will use `/tmp/bundler/home/discourse’ as your home directory temporarily.  
> gem install mini\_magick -v ~\> 4.8 -i /var/www/discourse/plugins/discussbook-plugin/gems/2.4.1 --no-document --ignore-dependencies  
> You are specifying the gem mini\_magick in /var/www/discourse/plugins/discussbook-plugin/plugin.rb, however it does not exist!

### Specifying in yml file

* * *

As it was not working, I tried to add the gem install command in yml file custom commands

> - exec: gem install mini\_magick -v 4.8.0

I get the following log(success) when it was being rebuilt

> I, [2017-07-08T18:50:43.302333 #13] INFO – : Beginning of custom commands  
> I, [2017-07-08T18:50:43.302751 #13] INFO – : \> gem install mini\_magick -v 4.8.0  
> I, [2017-07-08T18:50:44.034391 #13] INFO – : Successfully installed mini\_magick-4.8.0  
> 1 gem installed

But when I try to require it in the route, I got the following error in error log

> NameError (uninitialized constant) DiscussBook::DiscussbookController::MiniMagick)

Both of these trials did not work, can you please help me regarding what might be the error?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 9, 2017, 11:01am UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/2 "2017-07-09T11:01:36Z")

</div>

I don’t know, but you might make sure that the directory that is getting to write to is world writable.

---

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 9, 2017, 11:05am UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/3 "2017-07-09T11:05:04Z")

</div>

I can run the plugin locally… But in the server, the docker rebuild causes this issue.  
Are you suggesting that I should enter inside docker, and change the permissions of folder to writable?  
I will try that out, but if it would have been possible from plugin itself, it would be great.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 9, 2017, 12:48pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/4 "2017-07-09T12:48:05Z")

</div>

This is not how you include gems,

> [@Plugin with custom gems](https://meta.discourse.org/t/plugin-with-custom-gems/57190/4):
>
> Add your gem dependencies (all the dependency tree) to your plugin.rb file:

The version has to be specific, you can not use `~>`

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 9, 2017, 1:29pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/5 "2017-07-09T13:29:11Z")

</div>

Apparently, the most salient part of my earlier message was “I don’t know”. 🙂

---

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 10, 2017, 6:25pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/6 "2017-07-10T18:25:26Z")

</div>

Hi @sam, thanks for answer.  
I tried this many times in different configurations, but it failed. Then I came to know real cause, though I do not know the solution

When I install the `discourse-backups-to-dropbox` plugin from github (plugin that you shared), the docker builds properly. But if I put it `discourse-backups-to-dropbox` in private repository like bitbucket, it throws the error. The error logs for the plugin are same as shared in first post ie

> E -u discourse bundle exec rake db:migrate  
> ERROR: While executing gem … (Errno::EACCES)  
> Permission denied @ dir\_s\_mkdir - /var/www/discourse/plugins/discourse-backups-to-dropbox/gems  
> I, [2017-07-10T18:18:41.229582 #15] INFO – : `/root` is not writable.  
> Bundler will use `/tmp/bundler/home/discourse’ as your home directory temporarily.  
> gem install public\_suffix -v 2.0.5 -i /var/www/discourse/plugins/discourse-backups-to-dropbox/gems/2.4.1 --no-document --ignore-dependencies  
> You are specifying the gem public\_suffix in /var/www/discourse/plugins/discourse-backups-to-dropbox/plugin.rb, however it does not exist!  
> I, [2017-07-10T18:18:41.230126 #15] INFO – : Terminating async processes

So I guess the problem lies in the my private repo configuration. But if the plugin(without any gem) gets installed properly from bitbucket, I do not know why would installing plugin with gem throw error. It should not matter whether the plugin is in open repository like github or in private repo like bitbucket.

### My private repo config

> - exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
> - exec: mkdir /root/.ssh
> - exec: ssh-keyscan -t rsa [bitbucket.org](http://bitbucket.org) \> /root/.ssh/known\_hosts
> - exec: echo “Host bitbucket\n\tStrictHostKeyChecking no\n\tHostName [bitbucket.com](http://bitbucket.com)\n\tIdentityFile /root/.ssh/id\_rsa\n” \>\> /root/.ssh/config
> - file:  
> path: /root/.ssh/id\_rsa  
> chmod: 600  
> contents: |  
> -----BEGIN RSA PRIVATE KEY-----  
> …  
> …  
> -----END RSA PRIVATE KEY-----
> - file:  
> path: /root/.ssh/id\_rsa.pub  
> chmod: 600  
> contents: ssh-rsa …
> - exec: cd $home/plugins && git clone [git@bitbucket.org](mailto:git@bitbucket.org):path/to/discourse-backups-to-dropbox.git
> - exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
> - exec: cd $home && rm -fr tmp/cache
> - exec: cd $home && sudo -E -u discourse bundle exec rake assets:precompile
> - exec: rm /root/.ssh/id\_rsa
> - exec: rm /root/.ssh/id\_rsa.pub

Its same as mentioned in tutorial  
[https://meta.discourse.org/t/install-a-plugin/19157/33?u=net\_deamon](https://meta.discourse.org/t/install-a-plugin/19157/33)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 11, 2017, 11:02am UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/7 "2017-07-11T11:02:03Z")

</div>

I still don’t know.

If sounds like a permissions problem. You might `chmod - r 777` the repo after you clone it.

---

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 11, 2017, 5:28pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/8 "2017-07-11T17:28:50Z")

</div>

You are awesome @pfaffman. Thanks 🙂 👍

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [July 11, 2017, 5:39pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/9 "2017-07-11T17:39:46Z")

</div>

> [@pfaffman](#):
>
> chmod - r 777

That is one hell of a scary advice.  
I advise to figure out which user needs write permissions, and then `chown` it to that user, keeping the permissions at 0755.

---

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 11, 2017, 5:44pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/11 "2017-07-11T17:44:28Z")

</div>

Thanks 🙂 ,  
Yes I am now rebuilding with 755.  
Atleast I got to know where the issue was.  
I had been struggling with this for 3 days …

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 11, 2017, 6:06pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/12 "2017-07-11T18:06:04Z")

</div>

Yes. Once you see if that fixes it and what the ownership of the files created are, you should take steps to lock things back down.

---

<div class="post-metadata">

### Author: ![frank.manuel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frank.manuel/32/203348_2.png) [@frank.manuel](https://meta.discourse.org/u/frank.manuel)
#### Post date: [October 14, 2021, 4:29pm UTC](https://meta.discourse.org/t/specifying-the-gem-dependecies-for-plugin-gem-does-not-exist/65878/13 "2021-10-14T16:29:30Z")

</div>

I know this is an old issue, and that the solution has been found, but I encountered a similar problem and what I did to resolve it was:

1. Use a specific version, not “~\>”, as Sam says above
2. Version numbers should be “1.4.0” not just “1.4”, because while discourse installs “gemname-1.4.0” correctly, it looks for the declared “gemname-1.4” and fails.

Leaving this here in case it helps someone else who encounters this problem.
