Friday 2 November 2012

Package Installation and Updates

Apt and Package Basics

Most new users will use the Synaptic Package Manager to install packages. These instructions are for installing packages from the command-line Terminal. Terminal can be started:

Menu -> Applications -> Accessories -> Terminal
  • Install packages:
sudo apt-get install packagename  
  • Example:
sudo apt-get install mpd sbackup  
  • Remove packages:
sudo apt-get remove packagename  
  • To remove all dependencies:
sudo apt-get autoremove  
  • Example:
sudo apt-get remove mpd sbackup  
  • Search for packages:
apt-cache search <keywords>  
  • Examples:
apt-cache search Music MP3  apt-cache search "Text Editor"  
sudo apt-get update  
  • Upgrade packages:
sudo apt-get upgrade  
  • Upgrade the entire distribution (e.g. from Maverick to Natty):
sudo apt-get dist-upgrade  

Installing .deb packages

Debian (.deb) packages are the packages that are used in Ubuntu. You can install any .deb package in your system. .deb files can generally be installed from your file manager (Nautilus) merely by clicking on them, since file associations with the default installer is already set in Ubuntu. These instructions are for those who wish to install packages from the command-line terminal (Terminal).

  • Install a downloaded Debian (Ubuntu) package (.deb):
sudo dpkg -i packagename.deb  
  • Remove a Debian (Ubuntu) package (.deb):
sudo dpkg -r packagename  
  • Reconfigure/Repair an installed Debian (Ubuntu) package (.deb):
sudo dpkg-reconfigure packagename  
*Example:
sudo dpkg-reconfigure mpd  

Handling (Tar/GZip) and (Tar/Bzip2) archives

(Tar/GZip) archives end in ".tar.gz" and (Tar/Bzip2) archives end in ".tar.bz2". Bzip2 is the newer, more efficient compression method. These files can generally be automatically extracted by merely clicking on them from your file manager (Nautilus), since file associations with the appropriate archival utilities are set by default in Ubuntu. These instructions are for those who wish to use the command line Terminal.

  • To extract:
tar xvf packagename.tar.gz  

Note: tar is an application which can extract files from an archive, decompressing if necessary.

-x means extract.
-v means verbose (list what it is extracting).
-f specifies the file to use.
  • Decompressing ".gz" files
gunzip file.gz  
  • Decompressing ".bz2" files
bunzip2 file.bz2  
Note: You can also decompress a package first by using the command gunzip (for .gz) or bunzip2 (for .bz2), leaving the .tar file. You would then use tar to extract it.
  • To create a .gz archive:
tar cvfz packagename.tar.gz folder  
  • To create a .bz2 archive:
tar cvfj packagename.tar.bz2 folder  

Installing a package from source

  • Make sure you have all the necessary development tools (i.e. libraries, compilers, headers):
sudo apt-get install build-essential linux-headers-$(uname -r)  
Note: "uname -r" lists the current kernel you are using
  • Extract the archive that contains the source files:
tar xvf sourcefilesarchive.tar.gz  
  • Build the package using the package's script (in this case the configure script), compile the package (make), and install the compiled package into your system (make install):
cd /path/to/extracted/sourcefiles  ./configure  sudo make  sudo make install  
Note: typing ./ before a filename in the current folder allows the Linux shell to try and execute the file as an application even if it is not in the path (the set of folders which it searches when you type a command name). If you get a "permission denied" error, the file is not marked as being executable. To fix this:
sudo chmod +x filename  
Example: In the above instructions, configure is the shell script to build the package from source. To be sure the configure script is executable:
sudo chmod +x configure  
Create a .deb package from source files

If your build from source is successful, you can make a Debian (Ubuntu) package (.deb) for future use:

  • Install package tools:
sudo apt-get install checkinstall  
  • Rebuild package using "checkinstall":
cd /path/to/extracted/package  ./configure  sudo make  sudo checkinstall  
  • Keep the resulting ".deb" file for future use. It can later be installed using:
sudo dpkg -i packagename.deb  

Note: These are basic instructions that may not always work. Some packages require additional dependencies and optional parameters to be specified in order to build them successfully. Also see these Ubuntu wiki instructions. More info about .deb package structure can be found here.

No comments:

Post a Comment

Thanks for Visiting LinuxWorkstation