# Install a Theme programatically

**URL:** https://meta.discourse.org/t/install-a-theme-programatically/191843
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [May 27, 2021, 7:34pm UTC](https://meta.discourse.org/t/install-a-theme-programatically/191843 "2021-05-27T19:34:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [May 27, 2021, 7:34pm UTC](https://meta.discourse.org/t/install-a-theme-programatically/191843/1 "2021-05-27T19:34:54Z")

</div>

If you want to install themes via your `app.yml`, use the following format:

```yaml
run:
  - exec: echo "Beginning of custom commands"

  - file:
      path: /tmp/mythemes.yml
      contents: |
        discourse-gifs:
          url: https://github.com/discourse/discourse-gifs.git
          add_to_all_themes: true

  - exec:
      cd: $home
      cmd: su discourse -c 'bundle exec rake themes:install < /tmp/mythemes.yml'

  - exec: echo "End of custom commands"

```

## YAML format options

The YAML file supports a short format (URL only) and a long format with additional options:

```yaml
# Short format - just the URL
theme_name: https://github.com/example/theme.git

# Long format - with options
theme_name:
  url: https://github.com/example/theme_name.git
  branch: "main"
  private_key: ""
  default: false
  add_to_all_themes: false
  skip_update: false

```

| Option | Description |
| --- | --- |
| `url` | **(required)** The git repository URL |
| `branch` | Git branch to use (defaults to the repo’s default branch) |
| `private_key` | SSH private key for private repositories |
| `default` | Set as the default theme (boolean) |
| `add_to_all_themes` | For components only — install on every theme (boolean) |
| `skip_update` | Skip updating if the theme is already installed (boolean) |

## Installing from an archive

You can also install a theme from a local `.zip` or `.tar.gz` archive:

```plaintext
THEME_ARCHIVE=/path/to/theme.zip bundle exec rake themes:install:archive

```

Set `UPDATE_COMPONENTS=0` to skip updating included components.

> Last edited by @JammyDodger 2024-05-25T11:03:53Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![jimkleiber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimkleiber/32/121814_2.png) [@jimkleiber](https://meta.discourse.org/u/jimkleiber)
#### Post date: [May 4, 2022, 4:47pm UTC](https://meta.discourse.org/t/install-a-theme-programatically/191843/2 "2022-05-04T16:47:18Z")

</div>

Oh I’m so glad this is possible…I was trying to find a way to load themes across a multisite instance and this may be the easiest way. Thank you!

---

<div class="post-metadata">

### Author: ![chemol](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chemol/32/362270_2.png) [@chemol](https://meta.discourse.org/u/chemol)
#### Post date: [February 9, 2024, 10:29pm UTC](https://meta.discourse.org/t/install-a-theme-programatically/191843/3 "2024-02-09T22:29:22Z")

</div>

If anyone else is looking for a programmatical way to import a Theme from the local device with a zip file:

```plaintext
export THEME_ARCHIVE=<abolute-path-to-file> 
bundle exec rake themes:install:archive

```

or

```plaintext
THEME_ARCHIVE=<abolute-path-to-file> bundle exec rake themes:install:archive

```

is your friend.

---

<div class="post-metadata">

### Author: ![chemol](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chemol/32/362270_2.png) [@chemol](https://meta.discourse.org/u/chemol)
#### Post date: [February 17, 2024, 10:24pm UTC](https://meta.discourse.org/t/install-a-theme-programatically/191843/4 "2024-02-17T22:24:42Z")

</div>

(also works with tar.gz)
