Using Multiple Buildpacks for an App
Last updated May 15, 2023
There are many scenarios in which a single buildpack is not sufficient when building an application. This includes cases when you need to:
- Run a daemon process such as pgbouncer with your application.
- Pull in system dependencies with apt.
You can define the specific buildpacks your app needs and their order of execution with the Heroku CLI.
Setting a buildpack
You can use the
buildpacks:set command from the Heroku CLI to insert a single buildpack in your buildpack execution. For example, if you have a Ruby application, you might set this like so:
$ heroku buildpacks:set heroku/ruby
This command accepts an optional
--index argument, which can be used to set the position of the given buildpack in the order of execution. If
--index is provided, the command will overwrite the buildpack at the given position.
Adding a buildpack
You can add additional buildpacks to your application with the
buildpacks:add command. For example, if you need to add the Node.js buildpack to run a Grunt task you can add it with a command like this:
$ heroku buildpacks:add --index 1 heroku/nodejs
This will insert the Node.js buildpack at the first position in the order of buildpack execution, and move the other buildpacks that are ahead of it down one position. Thus the Ruby buildpack that was set in the previous example will now be the second buildpack to run.
The buildpack for the primary language of your app should always be the last buildpack in the list. This ensures that defaults for that primary language are applied instead of those for another language, and allows Heroku to correctly detect the primary language of your app.
You can view the complete list of buildpacks for an app by running this command:
$ heroku buildpacks
=== nameless-brushlands-4859 Buildpack
The last buildpack in the list will be used to determine the process types for the application. Any process types defined from earlier buildpacks will be ignored.
You can run
heroku help buildpacks to get a full list of options for the command.
Here are a few articles describing specific use cases for these commands:
For more information, see the primary Dev Center article on buildpacks.