Setting up your own Ubuntu repository on Dreamhost
Posted on: Monday, Sep 17, 2007
Following up on my post about installing a receipt printer on Ubuntu, I mentioned that I would post my experiences setting up a Ubuntu repository. Most of the documentation out there only covers setting up a repo on your own local machine, for your own local use only. On top of that, the docs vary between how much they tell you about the specifics of a Ubuntu vs Debian setup. Since I am likely not the only one trying to make this kind of thing, I’m posting a step-by-step guide on how to do it yourself.
We want to setup a publicly accessible Ubuntu repository so that we can distribute our own .deb packages to other users. Since we’re on a budget, we’re going to host this repo on our DreamHost account. Above all else, it needs to be easy to maintain, since we want this to make life easier, not harder.
We’re going to create a local repository on our development machine using dput and mini-dinstall. Then we’ll sync it to the remote web server using rsync and ssh.
As always, this guide assumes that you are familiar with Linux and are comfortable doing things on the command line. If not, turn back now, before it is too late! This is not a guide for beginners.
We’re also going to assume that you’ve got a hosting package with DreamHost, and a domain name to which you can add sub-domains.
Lastly, we’ll assume that your development machine is running some form of Ubuntu Linux. I used Feisty (7.04) when writing this article. Adjust the steps as needed for your own setup.
1. Set up a domain
To keep your website clean, it’s a good idea to set up a sub-domain of your primary site on which to host your repo. Using my site
www.drelmo.net as our example, we set up
packages.drelmo.net as our domain. On DreamHost, you want to set this up as a Fully Hosted Domain. If you know what you’re doing, you can customize the options on the setup screen, but the defaults are all fine.
2. Configure your SSH login to the new domain
To make life easier down the road, we’ll need a password-less SSH login to the site. I won’t go into the details of how to do this, as it has been documented far better in countless places. The DreamHost wiki, for example. I’ll assume from here on out that you can simply type “
ssh firstname.lastname@example.org” and get dropped into a bash shell.
Again, if you don’t understand that last sentence, stop now, before you hurt yourself.
3. Create a folder for the public repository
To keep things clean, I like to segment things a bit. This is an optional step, but one that I suggest doing unless you have a really good reason not to. Log into your server real quick and in the webroot, make a folder called ‘archive’. In the case of our example, this would go something like this:
4. Set up your repository… locally
I know, I know, we don’t care about having a local repo, we want to share it with the world! Sit tight, junior. This is part of the process. On shared hosting, you likely won’t have access to the tools needed to easily maintain a repository, and for good reason. So we’re going to set it up (and yes, keep it there) on our development machine first.
Rather than rewrite it, I’ll point you to the excellent guide that I followed called LocalAptGetRepository, over at the Ubuntu Community site. Follow that all the way down to (but not including) the section called “Changing your systems apt-get sources.list“.
All done? Great! Let’s move forward.
5. What you should have so far
At this point, you should have a folder somewhere on your dev machine that looks something like this:
And in those folders should basically be everything you need for your repo, hopefully with one or more packages already imported. If not, I suggest getting to that point before you move on.
6. Copying your local repo to the remote webhost
We can simply type in the
rsync command to get all our files up there, but we want this to be easy later on, remember? So let’s make a simple bash script that can do it all for us, so we don’t need to constantly retype the whole thing. I recommend calling it something simple like “
sync-repo“. Stick the following into it, making sure to adjust for your setup.
A few notes about the script: WordPress messes up the display of the rsync command, so there are two things to pay attention to.
- The three lines, starting with the rsync one, should all be on one line.
- The long dashes in front of “stats”, “progress”, and “exclude” should actually be two normal dashes.
rsync -rlptvzh --stats --progress --exclude=mini-dinstall
-e "ssh -l user" /home/marc/archive/
Now save the script,
chmod +x it, and run it! If all went well, you should be able to point your browser at the equivalent of
http://packages.drelmo.net/archive and see the same folder tree as the one on your machine. You’ll notice that we excluded the
mini-dinstall folder, because that should not be made public.
The Beautiful Finish
The final step is to add your brand new repository to your
/etc/apt/sources.list. Open up the list in your favorite editor:
sudo vim /etc/apt/sources.list
Then add in the lines for your repo:
deb http://packages.drelmo.net/archive feisty/
deb-src http://packages.drelmo.net/archive feisty/
Update your cache and you’re done!
sudo apt-get update
If you’ve followed along, you should now have your very own Ubuntu repository. To add new packages to it, just use
dput on your local machine, then run your
sync-repo script to update the online version. It’s that easy!