Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm building a .deb, and I need to do a few post-install commands (linking libraries paths, and a few other things).

Is there a way to have it so when you do a sudo dpkg -i <pacakage-name>.deb, a script runs?

share|improve this question
up vote 15 down vote accepted

You can execute commands after installation using the postinst shell script located in the debian folder in the source.

This is a normal shell script containing all the commands to be executed (in order) after the installation of the package. dpkg will run this automatically. So, all you need to do is create a shell script before packing your source package into a binary package, name it as 'postinst' and put it in the debian directory.

For more info, visit the Ubuntu Packaging Guide.

share|improve this answer
New Packaging Guide site: – Luis Alvarado Feb 21 '13 at 16:00
@LuisAlvarado link updated! thanks! – rigved Mar 24 '13 at 23:57
The page doesn't exist anymore... – Ionică Bizău Dec 28 '14 at 19:21
The page exists, the link is just wrong (it has a duplicate '/html' at the end). Correct link is . But perhaps the page has changed, because i found to be more useful. – Knetic Apr 29 '15 at 16:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.