How to update Ubuntu

$ sudo apt update
$ sudo apt upgrade

Info from man apt-get:

update is used to resynchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list. For example, when using a Debian archive, this command retrieves and scans the Packages.gz files, so that information about new and updated packages is available. An update should always be performed before an upgrade or dist-upgrade. Please be aware that the overall progress meter will be incorrect as the size of the package files cannot be known in advance.

upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.

dist-upgrade in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a “smart” conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. The dist-upgrade command may therefore remove some packages. The /etc/apt/sources.list file contains a list of locations from which to retrieve desired package files. See also apt_preferences(5) for a mechanism for overriding the general settings for individual packages.

The main distinction between apt-get upgrade and apt-get dist-upgrade is that in the former, none of the packages are removed. Software packages with newer versions are upgraded and none whatsoever are removed. In the latter, some newer packages are installed, and some are removed to satisfy certain dependencies.

Install Brave Browser on Ubuntu, MintDebian 9+, Ubuntu 14.04+ and Mint 17+

If you get gnutls_handshake() errors after adding the Brave repository on Debian 9, you may need to uninstall old conflicting packages.

# sudo apt install apt-transport-https curl gnupg
# curl -s | sudo apt-key --keyring /etc/apt/trusted.gpg.d/brave-browser-release.gpg add -
# echo "deb [arch=amd64] stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list
# sudo apt update
# sudo apt install brave-browser

Install Plesk on Ubuntu. Running the plesk installer results in failure.

Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming.
The following packages have unmet dependencies:
apache2 : Depends: apache2.2-common (= 2.2.22-13+deb7u3) but it is not going to be installed
apache2-mpm-prefork : Depends: apache2.2-common (= 2.2.22-13+deb7u3) but it is not going to be installed
Depends: apache2.2-bin (= 2.2.22-13+deb7u3) but it is not going to be installed
mysql-server : Depends: mysql-server-5.5 but it is not going to be installed
plesk-base : Depends: sw-engine (>= 2.13.8) but it is not going to be installed
plesk-core : Depends: libcurl3 (>= 7.16.2) but it is not going to be installed
awstats : Depends: perl:any
libapache2-mod-bw : Depends: apache2-api-20120211
libapache2-mod-perl2 : Depends: apache2-api-20120211
Depends: libxslt1.1 (>= 1.1.25) but it is not installable
Depends: libmyodbc but it is not installable
Depends: xsltproc but it is not installable
Depends: libtimedate-perl but it is not installable


The apg-get failed with the following message: Reading package lists... Building dependency tree... Reading state information... You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: apache2 :
Depends: apache2-bin (= 2.4.18-2ubuntu3.9) but 2.4.18-2ubuntu3.8 is to be installed
Depends: apache2-data (= 2.4.18-2ubuntu3.9) but 2.4.18-2ubuntu3.8 is to be installed linux-image-virtual:
Depends: linux-image-4.4.0-128-generic but it is not going to be installed plesk-service-node-utilities:
Depends: libidn2-0 (>= 0.6) but it is not going to be installed

Non-standard repositories enabled in /etc/apt/sources.list file that Plesk is not compatible with, so a system cannot resolve all the dependencies properly.

Connect to the server via SSH.

Replace all contents of the file /etc/apt/sources.list with the default content, like below:

Default sources.list for:
Ubuntu 18.04 LTS:

deb bionic main restricted universe
deb bionic-updates main restricted universe
deb bionic-security main restricted universe multiverse
deb bionic partner

Ubuntu 16.04 LTS:

deb xenial main restricted universe
deb xenial-updates main restricted universe
deb xenial-security main restricted universe multiverse
deb xenial partner

Update package lists and install missing dependencies:

apt-get update
# apt-get -f install

Run Plesk installation / update / upgrade.


Recently I ran a command in mysql that resulted in this error:


So I had to add a line to the mysql config file. In Ubuntu 16:

# nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add the following line under mysqld


Restart mysql:

# systemctl restart mysql

UFW is installed by default on Ubuntu. If it has been uninstalled for some reason, yYou can install it with apt-get:

# sudo apt-get install ufw

Check the Status

# sudo ufw status verbose

By default, UFW is disabled so you should see something like this:


# Status: inactive

If UFW is active, the output will say that it’s active, and it will list any rules that are set. For example, if the firewall is set to allow SSH (port 22) connections from anywhere, the output might look something like this:


Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere

Let’s set your UFW rules back to the defaults so we can be sure that you’ll be able to follow along with this tutorial. To set the defaults used by UFW, use these commands:

# sudo ufw default deny incoming
# sudo ufw default allow outgoing

As you might have guessed, these commands set the defaults to deny incoming and allow outgoing connections. These firewall defaults, by themselves, might suffice for a personal computer but servers typically need to respond to incoming requests from outside users. We’ll look into that next.

Allow SSH Connections

To configure your server to allow incoming SSH connections, you can use this UFW command:

# sudo ufw allow ssh

this command works the same as the one above:

# sudo ufw allow 22
# sudo ufw allow 2222

Now that your firewall is configured to allow incoming SSH connections, we can enable it

# sudo ufw enable

HTTP—port 80
HTTP connections, which is what unencrypted web servers use, can be allowed with this command:

# sudo ufw allow http

If you’d rather use the port number, 80, use this command:

# sudo ufw allow 80

HTTPS—port 443
HTTPS connections, which is what encrypted web servers use, can be allowed with this command:

# sudo ufw allow https

If you’d rather use the port number, 443, use this command:

# sudo ufw allow 443

FTP—port 21
FTP connections, which is used for unencrypted file transfers (which you probably shouldn’t use anyway), can be allowed with this command:

# sudo ufw allow ftp

If you’d rather use the port number, 21, use this command:

# sudo ufw allow 21/tcp

Allow Specific Port Ranges
You can specify port ranges with UFW. Some applications use multiple ports, instead of a single port.

For example, to allow X11 connections, which use ports 6000-6007, use these commands:

# sudo ufw allow 6000:6007/tcp
# sudo ufw allow 6000:6007/udp

When specifying port ranges with UFW, you must specify the protocol (tcp or udp) that the rules should apply to. We haven’t mentioned this before because not specifying the protocol simply allows both protocols, which is OK in most cases.

Allow Specific IP Addresses
When working with UFW, you can also specify IP addresses. For example, if you want to allow connections from a specific IP address, such as a work or home IP address of, you need to specify “from” then the IP address:

# sudo ufw allow from

You can also specify a specific port that the IP address is allowed to connect to by adding “to any port” followed by the port number. For example, If you want to allow to connect to port 22 (SSH), use this command:

# sudo ufw allow from to any port 22

Allow Subnets
If you want to allow a subnet of IP addresses, you can do so using CIDR notation to specify a netmask. For example, if you want to allow all of the IP addresses ranging from to you could use this command:

# sudo ufw allow from

Likewise, you may also specify the destination port that the subnet is allowed to connect to. Again, we’ll use port 22 (SSH) as an example:

# sudo ufw allow from to any port 22

Allow Connections to a Specific Network Interface
If you want to create a firewall rule that only applies to a specific network interface, you can do so by specifying “allow in on” followed by the name of the network interface.

You may want to look up your network interfaces before continuing. To do so, use this command:

ip addr
Output Excerpt:
2: eth0:  mtu 1500 qdisc pfifo_fast state
3: eth1:  mtu 1500 qdisc noop state DOWN group default 

The highlighted output indicates the network interface names. They are typically named something like “eth0” or “eth1”. So, if your server has a public network interface called eth0, you could allow HTTP traffic (port 80) to it with this command:

# sudo ufw allow in on eth0 to any port 80

Doing so would allow your server to receive HTTP requests from the public Internet.

Or, if you want your MySQL database server (port 3306) to listen for connections on the private network interface eth1, for example, you could use this command:

# sudo ufw allow in on eth1 to any port 3306

This would allow other servers on your private network to connect to your MySQL database.

Deny Connections
If you haven’t changed the default policy for incoming connections, UFW is configured to deny all incoming connections. Generally, this simplifies the process of creating a secure firewall policy by requiring you to create rules that explicitly allow specific ports and IP addresses through.

To write deny rules, you can use the commands that we described above except you need to replace “allow” with “deny”.

For example to deny HTTP connections, you could use this command:

# sudo ufw deny http

Or if you want to deny all connections from you could use this command:

# sudo ufw deny from

If you need help writing any other deny rules, just look at the previous allow rules and update them accordingly.

Now let’s take a look at how to delete rules.

Delete Rules
Knowing how to delete firewall rules is just as important as knowing how to create them. There are two different ways specify which rules to delete: by rule number or by the actual rule (similar to how the rules were specified when they were created). We’ll start with the delete by rule number method because it is easier, compared to writing the actual rules to delete, if you’re new to UFW.

By Rule Number
If you’re using the rule number to delete firewall rules, the first thing you’ll want to do is get a list of your firewall rules. The UFW status command has an option to display numbers next to each rule, as demonstrated here:

# sudo ufw status numbered
Numbered Output:
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22                         ALLOW IN
[ 2] 80                         ALLOW IN    Anywhere

If we decide that we want to delete rule 2, the one that allows port 80 (HTTP) connections, we can specify it in a UFW delete command like this:

# sudo ufw delete 2

This would show a confirmation prompt then delete rule 2, which allows HTTP connections. Note that if you have IPv6 enabled, you would want to delete the corresponding IPv6 rule as well.

By Actual Rule
The alternative to rule numbers is to specify the actual rule to delete. For example, if you want to remove the “allow http” rule, you could write it like this:

# sudo ufw delete allow http

You could also specify the rule by “allow 80”, instead of by service name:

# sudo ufw delete allow 80

This method will delete both IPv4 and IPv6 rules, if they exist.

How To Disable UFW (optional)
If you decide you don’t want to use UFW for whatever reason, you can disable it with this command:

# sudo ufw disable

Any rules that you created with UFW will no longer be active. You can always run sudo ufw enable if you need to activate it later.

Reset UFW Rules (optional)
If you already have UFW rules configured but you decide that you want to start over, you can use the reset command:

# sudo ufw reset

This will disable UFW and delete any rules that were previously defined. Keep in mind that the default policies won’t change to their original settings, if you modified them at any point. This should give you a fresh start with UFW.

How can I increase the space on an Ubuntu Boot Partition?

When trying to install programs on my Ubuntu server but the server is not allowing me to do that because the boot partition ‘/dev/sda1’ is full.

/dev/sda1       236M   236M  0M  100% /boot

By default Ubuntu has a small /boot partition. When you have auto updates enabled this can cause some issues as newer kernels are not automatically purged. So, you will need to increase the size of the Ubuntu Boot Partition.

You can add the following to your crontab to run every Sunday night at 11:30PM to clean out old kernels. You can do so by running crontab -e as root and adding the following line at the bottom of that file.

30 23 * * 6 apt-get autoremove

You will also want to reboot every so often so newer kernels are being used and newer kernels are not causing the issues. I would suggest rebooting at your earliest convenience and running

# apt-get autoremove 

to load the newest kernel and delete the older kernels already installed on your server.

However, once rebooted and the autoremove command is done more disk space will be free.


$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            990M  4.0K  990M   1% /dev
tmpfs           201M  716K  200M   1% /run
/dev/dm-0        15G  1.9G   12G  14% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M     0 1001M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sda1       236M   72M  152M  32% /boot

$ du -shcx /boot/*
1.2M /boot/abi-3.16.0-30-generic
1.2M /boot/abi-3.16.0-77-generic
169K /boot/config-3.16.0-30-generic
169K /boot/config-3.16.0-77-generic
6.7M /boot/grub
21M /boot/initrd.img-3.16.0-30-generic
21M /boot/initrd.img-3.16.0-77-generic
du: cannot read directory ‘/boot/lost+found’: Permission denied
12K /boot/lost+found
174K /boot/memtest86+.bin
175K /boot/memtest86+.elf
176K /boot/memtest86+_multiboot.bin
3.4M /boot/
3.4M /boot/
6.1M /boot/vmlinuz-3.16.0-30-generic
6.2M /boot/vmlinuz-3.16.0-77-generic
70M total


How to install PHP 5.6 on Ubuntu 16.04 Xenial and replace php 7. Let’s assume you have a fresh Ubuntu 16.04 server.

Install add-apt-repository:

# sudo apt-get install python-software-properties

Add repository for PHP 5.6:

# sudo add-apt-repository -y ppa:ondrej/php

Update package lists:

sudo apt-get update

Install php5-fpm:

# sudo apt-get install php5.6-fpm

Check the result:

# php -v
PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Run the following:

# sudo mv /usr/bin/php /usr/bin/php7
# sudo mv /usr/bin/php5.6 /usr/bin/php

Check again

# php -v
PHP (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Restart Apache

# service apache2 restart