# How to install import script gem dependencies?

**URL:** https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229
**Category:** Development
**Created:** [October 30, 2016, 12:51pm UTC](https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229 "2016-10-30T12:51:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tobiasmuehl](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@tobiasmuehl](https://meta.discourse.org/u/tobiasmuehl)
#### Post date: [October 30, 2016, 12:51pm UTC](https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229/1 "2016-10-30T12:51:27Z")

</div>

Some import scripts are using external dependencies, and those seem to work just fine.

When trying to add my own Gemfiles, I’m always presented with

```plaintext
/usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- redcarpet (LoadError)
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
        from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
        from emed.rb:4:in `<main>'

```

I’m installing the gem using the root user inside the docker image since the discourse user isn’t privileged enough, and the gem’s can be run from the command line from the discourse user just fine. Just `require redcarpet` doesn’t work.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [October 30, 2016, 2:41pm UTC](https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229/2 "2016-10-30T14:41:31Z")

</div>

I recommend adding your dependency to the Gemfile and using bundler to install the gems. Run this inside the Docker container:

```bash
cd /var/www/discourse
echo "gem 'my_gem'" >> Gemfile
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

```

And you need to run your import script as user `discourse` as well:

```bash
su discourse -c 'bundle exec ruby script/import_scripts/my_import_script.rb

```

---

<div class="post-metadata">

### Author: ![tobiasmuehl](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@tobiasmuehl](https://meta.discourse.org/u/tobiasmuehl)
#### Post date: [October 31, 2016, 9:02am UTC](https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229/3 "2016-10-31T09:02:49Z")

</div>

Thanks for the reply. Installing the gem using bundler worked the way you suggested, however running the import script with bundler didn’t work. Used `su discourse -c 'ruby script/import_scripts/my_import_script.rb'` instead, that worked

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 23, 2019, 5:51am UTC](https://meta.discourse.org/t/how-to-install-import-script-gem-dependencies/52229/4 "2019-03-23T05:51:35Z")

</div>


