Monday, July 13, 2015

How to setup a local repository in Ubuntu (with images)

Now I'll show you how to setup a local repository in an Ubuntu Server. This can be helpful when you want to take control of the Linux machines in your organization's environment. Let's begin:

1. Open a terminal
2. Install the Debian Package Development Tools. To do that, enter the following command in the the Terminal: 

sudo apt-get install dpkg-dev

Note: I'm using Ubuntu 14.04 LTS and the package is already installed in this version.
Ubuntu dpkg installed
3. Crete a directory for the packages. When you download any packages from the local repository, they will be saved here. To do this, just enter the following command: 

sudo mkdir -p /usr/local/mypackages

In this case, I'm using the folder: /usr/local/mypackages as the place to hold the packages fro the local repository.

4. Create a script that will scan the packages in the destination folder and will create a file that can be read by apt-get. To do this, enter the following commands in the terminal:

  • sudo gedit (this opens a text editor. If you don't have it already installed, enter: sudo apt-get install gedit)
  • When Gedit opens, paste the following text into Gedit:
#! /bin/bash
 cd /usr/local/mypackages
 dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Gedit script

  • Go to File > Save As.
  • Go to Home > User  > bin, where 'User' is your user name (e.g., Home/Jorge/bin). If you don't have a bin folder, create it.
  • Save the file as: update-mypackages
Saving a file

  • Close Gedit
5. Make the script executable:

sudo chmod u+x ~/bin/update-mypackages

6. Open the sources.list file:
  • In the terminal, enter sudo gedit
  • From the Gedit window, click Open.
  • Browse to /etc/apt and open sources.list
Packages sources list

  • Go to the end of the file and add the following line:
deb file:/usr/local/mypackages ./

Adding a new source

  • Click 'Save' and close Gedit.
And that's all. A simple repository is running in your Ubuntu Server. Now let's test it.

1. Download the .deb file for Notepad++ here.
2. Now, copy the file into the folder you created for packages: /usr/local/mypackages (you might need to use sudo mv)
3. Run the script you created in ~/bin ('~' means your home directory) with the following command:
sudo ./update-packages
Result of the script

4. Update apt-get: sudo apt-get update
5. Now, to test if the local repository is working, disconnect from Internet. 
6. Run this command to install the package:
sudo apt-get install notepad++

If everything went well, you'll see something like this:
Installing from local repository

There's a lot to say about creating a local repository in Linux, but I think this is a good starting point. I'll be writing more about this in future posts.

0 comentarios:

Post a Comment