I recently installed QGIS 3.1 in my Ubuntu 18.04. I faced a few issues which were eventually resolved by referring and trying out different solutions over the web. So to make things smoother for everyone else, I decided to condense and document the installation process in a single blog post.

Step 1: Add QGIS 3 Repository in the list of data sources of Ubuntu

You will need to add the QGIS Repository URL in the sources.list file of our Ubuntu. You can do that by running in your terminal the following command:

sudo nano /etc/apt/sources.list

This will open up the sources.list file in your terminal - being edited by the utility 'nano'. Now navigate to the bottom of this file, add the following line:

deb https://qgis.org/debian bionic main

You will need to save the sources.list file by pressing "Ctrl+X" followed by "Y" indicating that you wish to save this file. With this, you have informed Ubuntu to look for the QGIS package for your Ubuntu version - 18.04 code-named 'bionic' at the URL 'https://qgis.org/debian'.

For secure communication between your machine and the QGIS Server, the Public-key (Asymmetric) Cryptography using GPG is used. This requires that you import the latest public key from the QGIS Server.

Step 2: Importing latest Public Key from QGIS Server

This is the step where the tutorials that I found on the web, mentioned an earlier version of the key - which did not work for me. You can import the latest version of the key by running the following command in your terminal:

wget -O - http://qgis.org/downloads/qgis-2019.gpg.key | gpg --import

To validate and verify the key's ownership, run the following command in the terminal:

gpg --fingerprint 51F523511C7028C3

You should ensure that the result of the above command contains 'QGIS Archive Automatic Signing Key (2019) <qgis-developer@lists.osgeo.org>'.

Now you need to export this key in the ASCII armored format and add it to 'apt-key' - the key management utility of the apt package manager. You can do it by running the following command on your terminal:

gpg --export --armor 51F523511C7028C3 | sudo apt-key add -

Step 3: Update your Package List

This is probably the most popular command when it comes to updating and maintaining Linux. Run the following command in your terminal:

sudo apt-get update

For the inquisitive ones out there, this StackOverflow thread is a good read on this.

Step 4: Installing the QGIS Package and a Few Others

Run the following command in your terminal:

sudo apt-get install qgis python-qgis qgis-plugin-grass

When prompted, press "Y" and the installation will start. Once done, you need to verify the installation by either running in the terminal:

qgis

Or simply by searching for 'QGIS' in your applications(by pressing the Windows key). Clicking on the QGIS Desktop or by running the above command should show a spash screen and start QGIS.

You have successfully installed QGIS!

I am sincerely grateful to the authors of other tutorials and discussion forums(StackOverflow and Github Issues) on this topic, without whose efforts, I could not have installed QGIS on my machine. Here are the list of web pages, I referred: