Install the latest version of Composer on Ubuntu

If you have previously installed composer with command...

sudo apt-get install composer is recommended to uninstall it first. Run the command:

sudo apt-get purge --auto-remove composer


Let's install the latest version now. Go to whatever directory you like and follow the instructions for Command-line installation on the official Composer website:

After you run the four commands (copy, verify, install, remove), you should end up with a single file named composer.phar.

All you have to do now is move this file to the appropriate directory with a command:

sudo mv composer.phar /usr/local/bin/composer

Try running this command anywhere...

composer -V

...and you should see the latest version of your freshly installed Composer.


Running composer might display this error message (where [user] is your username):

Cannot create cache directory /home/[user]/.composer/cache/repo/, or directory is not writable.
Proceeding without cache
Cannot create cache directory /home/[user]/.composer/cache/files/, or directory is not writable.
Proceeding without cache

Set the permissions with these commands (where [user] is your username):

cd ~
 sudo chown [user]:[user] .composer -R

How to remove old kernel versions on Ubuntu Server

It is recommended to remove old kernel version to clean up the boot menu and to get some extra disk space.

1. Check which kernel version you're using:

uname -r

2. List all installed kernels and headers on your system:

dpkg -l | grep linux-image
dpkg -l | grep linux-headers

3. If you're not using the latest kernel version, try rebooting your system first.

4. You can remove old kernel versions automatically:

sudo apt-get autoremove

5.a. Or you can remove them manually one by one:

sudo apt-get purge linux-image-x.x.x.x-generic

Be sure, NOT to remove the version you're using! 

It is also recommended to leave the previous version on your system.

5.b. When you're done, update your Grub:

sudo update-grub2 

6. Reboot your system.

Disk Space and Partitions on Linux and UNIX-like systems

Disk Space

We can check out free disk space on a Linux system with the command:

df -h


df -k

These commands are great for checking overall disk space usage, but since we usually want to check which folder (or file) occupies the most disk space, we can run the command:

du -sh * | sort -hr

The first part of the command (left side of the pipe) will return the list of files and folders with corresponding disk usage values.

The second part (right side of the pipe) will sort the results by size (disk space usage) and will put the largest sizes on the top of the list. If you want the largest sizes on the bottom, just remove the 'r' parameter (r - reverse).

This command will list only the files and folders in the path where you are located, when running this command.

A suggestion:

Run the command, then 'cd' into the largest directory and run the command again. By doing that a few times, you will most likely find the source of your largest files and directories.


Disk Partitions

List all partitions and check their size:

sudo fdisk -l /dev/sda

Open Linux partition editor in terminal:

sudo cfdisk

Rsync - copy multiple files from one server to another

Rsync is a file transfer program capable of efficient remote update via a fast differencing algorithm.

Rsync utility is commonly found on Unix-like systems and is used to minimize network usage while copying (or synchronizing) files from one server to another.

If you have SSH access to your server you can use rsync instead of traditional FTP method.

How to use rsync?

Let's say, that you want to copy files from server Master to server Slave. You must have SSH access to both servers.

  1. SSH to your Master server (How-to guide here)

  2. Enter the command:
    rsync -a /path/to/your/files/ slave@
    Be sure to use your own username and IP instead of slave@

  3. You're done, the files are copied now.

Parameter '-a' explained

Parameter -a (or --archive) is 'archive mode' and is equal to -rlptgoD

-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p keep partially transferred files & show progress during transfer
-t, --times preserve modification times
-g, --group preserve group
-o, --owner preserve owner (super-user only)
-D preserve device files (super-user only) & preserve special files

Install VMware tools on Ubuntu Server

1. Enable Shared folders

Edit virtual machine settings, go to Options / Shared folders, set to Always enabled and add a host folder to the Folders list. Run virtual machine and login to Ubuntu Server with your username and password.

2. Update package repository

sudo apt-get update

3. Instal dependencies

sudo apt-get install gcc binutils make linux-source

4. Start with the VMware Tools installation

Click "Install VMware Tools..." in the window menu of the virtual machine. If the prompt window appears (Disconnect anyway and override the lock?), click Yes.

5. Create mount directory for CD-ROM

sudo mkdir /mnt/cdrom

6. Mount virtual CD-ROM to created folder

sudo mount /dev/cdrom /mnt/cdrom

7. Extract .tar file

sudo tar xzvf /mnt/cdrom/VMwareTools-?.?.?-???????.tar.gz -C /tmp/

Tar file should be named as the file that is listed in the /mnt/cdrom folder.

8. Navigate to the extracted location

cd /tmp/vmware-tools-distrib

9. Run installation

sudo ./ -d

10. Reboot the system and the VMware Tools are installed.

sudo reboot

Package repositories on Ubuntu Server

Package repositories

Update the package repositories from sources with the latest versions

sudo apt-get update

A list of repositories, that the server will check for packages, is stored at /etc/apt/sources.list

cat /etc/apt/sources.list

Extra repositories can be added to /etc/apt/sources.list.d

Package information

Search for available packages (eg. mysql); to search only by the package name, use -n tag.

sudo apt-cache search mysql
sudo apt-cache search -n mysql

Get the package information (eg. mysql-server-5.6)

sudo apt-cache show mysql-server-5.6

Install/uninstall a package

Install a package || without prompting use tag -y || for quiet install use tag -qq

sudo apt-get install -y mysql-server-5.6

Uninstall a package ('purge' removes the configuration, 'remove' removes only the package)

sudo apt-get purge mysql-server-5.6

After uninstalling use autoremove to remove any dependencies that are not in use by other packages

sudo apt-get autoremove

List all installed packages

Get a list of packages installed locally (the -v tag "inverts" grep to return non-matching lines)

dpkg --get-selections | grep -v deinstall

Get a list of a specific package installed

dpkg --get-selections | grep mysql

Alternatively, simply use

dpkg -l

Get just the packages which were expressly installed (not just installed as dependencies)

aptitude search '~i!~M'


Install & configure Samba Server on Ubuntu VM

1. Install Samba

The first thing we need to do is to update the package repositories and then install Samba.

sudo apt-get update
sudo apt-get install samba

2. Configure Samba

Now we'll have to add a few lines to the Samba configuration file /etc/samba/smb.conf to make everything work.

# The following property ensures that the existing files do not have their
# permissions reset to the "create mask" (defined below) if they are changed
map archive = no

# Notify upon file changes so that Windows can detect such changes
change notify = yes

# Configure shared folder for your user where "developer" is your Linux username
comment = Developer Files
path = /home/shared
guest ok = no
browseable = yes
writable = yes
create mask = 0664
directory mask = 0775

Save and close the config file and then add a Samba user and password identical to your Linux user account.

sudo smbpasswd -a developer

Restart Samba so that the config can be re-read.

sudo service smbd restart

Your Windows host should now have access to the shared folder. To access the shared folder, open a folder browser and type in:

\\*ubuntu-local-ip-address*\developer (e.g. \\\developer)

To find out what your local IP address is, got to your Ubuntu server terminal and type:




Configure SSH to connect to a Remote Ubuntu Server

1. On your Windows machine I suggest installing Cmder console emulator, visit and then download and install the Full package (with git-for-windows)

2. Open Cmder or other console software on your Windows machine, navigate to root directory, create .ssh directory and enter it

cd ~
mkdir .ssh
cd .ssh

3. Create SSH key pair id_rsa & (-t is type, -b is bytes, -f is filename)

ssh-keygen -t rsa -b 4096 -f id_rsa -C ""

4. Display the public key on the screen, select the printed text and copy it to clipboard


5. Login to your Ubuntu Server and install OpenSSH in case you don't have it yet

sudo apt-get install openssh-server

Before you do that, don't forget to update the repositories with:

 sudo apt-get update

6. On your Ubuntu Server machine, navigate to root directory, create .ssh directory and enter it

cd ~
sudo mkdir .ssh
cd .ssh 

7. Create a file authorized_keys and open it for edit

touch authorized_keys 
nano authorized_keys 

6. Paste previously copied public key and paste it to this file

7. Logout from Ubuntu Server and try to login from your Windows machine

ssh username@

(use your own Ubuntu Server root username & IP address)

8. If you're connecting to eg. GitHub via SSH, test your connection with this command:

ssh -T

Copy public SSH key to your server

When you create SSH key pair on your computer, you can copy the public key to your server via terminal (console).

cat ~/.ssh/ | ssh username@ 'cat >> .ssh/authorized_keys && echo "Key copied"'

Configure static local IP on Ubuntu Server

1. Login to your Ubuntu Server and check your networking

eth0 Link encap:Ethernet         HWaddr 00:0c:29:7c:05:22 
     inet addr:     Bcast:  Mask:
     inet6 addr: fe80::20c:29ff:fe7c:522/64 Scope:Link

2. Edit the network config file »interfaces«

sudo nano /etc/network/interfaces

3. You will see these two lines

auto eth0 
iface eth0 inet static

4. Change the lines to this configuration (don't mind the comments)

auto eth0 
iface eth0 inet static            #dynamic is changed to static
address            #your custom local IP
netmask             #same as on ifconfig Mask
gateway               #default local network IP
broadcast           #same as on ifconfig Bcast
dns-nameservers   #Google's DNS servers

5. Save the file and restart networking

sudo /etc/init.d/networking restart

6. Check your local static IP

eth0 Link encap:Ethernet          HWaddr 00:0c:29:7c:05:22 
inet addr: Bcast: Mask:
inet6 addr: fe80::20c:29ff:fe7c:522/64 Scope:Link

7. Important: if you're doing this on virtual machine (VirtualBox, VMware), you may have to reboot

sudo reboot