Buscar

Mostrando entradas con la etiqueta Ahmed Bilal. Mostrar todas las entradas
Mostrando entradas con la etiqueta Ahmed Bilal. Mostrar todas las entradas

Linux Package Manager: The Debian Style

The author of this post is: Ahmed Bilal Jan (linkedin.com)

If you have just started using Linux you probably will be saying why people call this operating system an unfriendly?

It’s has almost everything that an operating system has to be classified as user friendly.

Believe me those were opinions of people who used Linux back in early 2000.

I remember when I started using Linux back in 2007 I have to issue mount command in shell to mount my USB stick for using it on Redhat Linux.

As a student we were mostly reluctant in using Linux since we were told that you can’t play your media files in Linux. Excuse me!!! No media files? Our answer was no media files means no computer for us.

Though there were many other such limitations in those days that classify Linux as an operating system only for experts only.

We were happy to use Windows in those days since we can easily play our media files in it.

One of the most challenging thing at that time was installing a software on your Linux distribution.

You download a tar file from Internet and go through its readme file and then when you start installing it you were prompted that the software you trying to install has dependency on some X library when you try to install X library you were told that X has dependency on Y please install first Y and the story continuous on.

Thanks to Linux package manager users nowadays don't have to bear all that.

In this article I am going to explain how package manager works in a Debian based distribution.

Although name of package manger differs in rpm based distribution but the principle on which package manager works remain the same.

In Debian based distribution the installable binaries of software came in the form of files with .deb extension.
 
To install these .deb files, there is a command line tool available called dpkg, short for Debian package manager.

The dpkg only install the .deb file which is passed to it as an argument. It doesn't take the responsibility of installing the dependency files and also no configuration setting is being done by dpkg.

You can say dpkg is manual method of installing a file. For example to install a package we issue following command in terminal:

    $ sudo dpkg -i packagename.deb
 
To view all installed packages:

    $ sudo dpkg -l

To remove a package let say name tcl, we use:

    $ sudo dpkg -r tcl

To find out which package a file belongs. Let say we need to find package of networkctl file:

    $ sudo dpkg -S /bin/networkctl

There is no guarantee that software which you are trying to install may got installed in first go. It may prompt you with message that software you trying to install is dependent on some library which is missing please install it first.

To overcome the limitations of dpkg, software developers invented the apt-get utility for Debian based distribution.

It is referred as front end of dpkg in a sense that real package manager is still dpkg.

A part from installing new software apt-get do the dependency work for you, as its automatically install all dependencies and also do configuration settings for you.

The apt-get can also be used to un-install a package and update a package. Some example of apt-get utility are:

To install a package:

    $apt-get install [package name]

To remove a package:

    $apt-get remove [package name]

There are three apt-get commands: update, upgrade and dist-upgrade

    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get dist-upgrade

The update command only update the list of available packages and their versions, but it does not install or upgrade any packages.

While the upgrade command upgrade the software installed on your system.

It is recommended that you should first run “apt-get update” so that package manager knows the latest version of software available.

The third one “apt-get dist-upgrade” do the same thing of updating softwares installed on your distribution. In addition “apt-get dist-upgrade” also smartly handles the  dependencies.

It also intelligently handles changing dependencies with new versions of packages.

There is GUI version of apt-get as well. To install GUI version of apt-get use following command:

    $ sudo apt-get install synaptic

You can access synaptic by tying synaptic in terminal. Synaptic can do all tasks which can be done by command line apt-get like installing, un-installing and updating package.

One important thing to mention here is repositories.

You can see repositories in file /etc/apt/sources/list.

Whether you use command line utility like apt-get or its GUI counterpart they both make use of repository in /etc/apt/sources.list.

If you open this file you will see lines starting with deb followed by web links.

A repository is collection of software for your distribution on server.

Your package manager apt-get or synaptic goes to these servers and grab the software you want to install along with their dependencies files. A typical line in /etc/apt/sources.list looks like this:


deb http://pk.archive.ubuntu.com/ubuntu/ xenial main restricted

You may enable or disable lines in repository. Lines starting with # are considered disabled.

Linux package manager can safely be classified as one of the factor which makes Linux an operating system for home use. Without this utility it will be very hard for Linux to be classified as an OS for everyone.

Linux: Directory Structure


The author of this post is: Ahmed Bilal Jan (linkedin.com)

Linux file system or directory structure looks very strange to most of Linux users in their early days of encounter with Linux.

In this article I want to review some of key areas of Linux file system which may help new Linux users in getting familiar with it.

Please do not confuse file system with a format on how operating system stores files on hard disk, here by file system we mean how a Linux operating system organizes a data on individual computer.

Linux file system is derived from UNIX file system where it stores files in hierarchical tree. The top of this hierarchical tree structure is referred as root directory.

Linux consider everything as a file. Your hardware (HDD, Pen drives, CD ROM), boot media (Kernel, boot loader), configuration settings, user accounts etc from the eyes of Linux operating system all of them are files.

It’s a famous quote about Linux that “In Linux everything is file, if it’s not a file it’s a process”. So it’s very important for us to know how Linux directory structure is organized.

To get started use ls command, for example: ls / -l and you will be displayed with a folder which in turns contains many other directories like  bin, boot, cdrom, media, mnt, lib, var, root and many others.

What these folders contain? to answer we need to just go back and see what I wrote “Linux consider everything as a file”.

Your entire computer which Linux operating system sees is stored in these directories as files. Yes everything.

From binary executable of software you install on your hard disks to your configuration settings, from your boot media to user accounts, from operating system libraries to even your keyboard everything is file and is stored somewhere in a directory under “ / ”.

This “ / ” is refereed as root directory it has no parent directory everything else follow this directory.

It's very important for new comers to browse these directories under “ / ”  and then start understanding what each directory contains.

Just for illustration I am going to write one line description of important directories.

/bin: Binaries of command executed in shell reside here. Shell available for your distribution also reside here.

/boot: Files required for starting Linux resides here. Linux kernel, boot loader configuration files reside here.

/cdrom: Just for legacy support this directory is created to mount CD-ROM.

/dev: All hardware attached to your computer resides here in the form of files like HDD,keyboard,mouse.

/etc: Contains configuration files. This is one of most important directory.

/home: Contains home directories for users created on system.

/lib & /lib64: 32-bit and 64-bit libraries and kernel modules resides here respectively.

/media: External devices like HDD can be mounted here. Its just for legacy support.

/mnt: Also used as mounting point but specifically for temporarily mounted devices.

/opt: Software not managed by package manager reside here.

/proc: Contains runtime system information. It provides mechanism for kernel to send information to processes.

/run: Contains daemons which are required at very early stage of boot like systemd and udev.

/root: It’s the superuser/root user home directory.

/sbin: It's short of system binary. Contains binary files of important administrative commands.

/srv: Contains directories for services like HTTP/FTP.

/var: Contains variable data like log files, database files.

You should also know how to browse Linux directory structure via command line as GUI is not always available in Linux specially if you are working on Linux  server. There are few commands I would like to talk about.

$ pwd
: This command prints out your current directory. If you forget where you are, use this.

$ ls: This command is used to display contents of your current directory. Directory name are displayed in color form. Always use this to browse contents of directory.

$ tree: Display contents of directory in tree like form.

So question pops up in everyone mind. Does this Linux directory structure has any advantage? Yes it does. 


As you browse directories under root directory you may see that similar files are stored under same directory like logs files are under /var/log , binaries of commands executed in shell are stored in /bin,  library files are found under /lib and /lib64 and so on.