Ubuntu
Ubuntu
#ubuntu
Table of Contents
About 1
Remarks 2
What is Ubuntu? 2
Versions 2
Examples 3
Installation or Setup 3
What is Ubuntu 3
Installation 3
Examples 6
Remarks 8
Examples 8
!! 9
Restart Ubuntu 11
DPKG 12
Chapter 4: Networking 16
Examples 16
Remarks 18
Examples 18
Syntax 20
Parameters 20
Examples 20
Remarks 22
Examples 22
Credits 24
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: ubuntu
It is an unofficial and free Ubuntu ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official Ubuntu.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to [email protected]
https://riptutorial.com/ 1
Chapter 1: Getting started with Ubuntu
Remarks
What is Ubuntu?
Ubuntu is an open source software platform that runs everywhere from the smartphone, the tablet
and the PC to the server and the cloud.
• The fastest route from development to deployment on desktop, mobile, server or cloud
• The desktop of choice for developers at some of the world's leading technology companies
• The broadest and best development tools and libraries
• Lightweight to either run natively or in a VM, on a PC or a Mac
• Ideal for any resource-intensive environment
Ubuntu is used by thousands of development teams around the world because of its versatility,
reliability, constantly updated features, and extensive developer libraries.
If you're managing developers, Ubuntu is the best way to increase your team's productivity and
guarantee a smooth transition from development all the way to production. Ubuntu is the world’s
most popular open source OS for both development and deployment, from the data centre to the
cloud.
And, as the Ubuntu OS converges, these same applications will be able to run on desktop, tablets,
phone and even on the Internet of Things — one application across Ubuntu's full range of devices.
Versions
https://riptutorial.com/ 2
15.04 22-Apr-2016 13:55 Ubuntu 15.04 (Vivid Vervet)
Examples
Installation or Setup
What is Ubuntu
Ubuntu is an open source software platform, but colloquially, when Ubuntu is referred to it's mainly
toward the Ubuntu operating system. Ubuntu is based on Debian and uses the same package
management system (deb and apt).
Installation
So you want to give Ubuntu a try! That's great. First off, let's grab the Ubuntu .iso file that you'll be
needing to install the operating system on your system. Note, an .iso file is an image file that we
can burn to a USB/CD. Think of it as a snapshot of the Ubuntu Operating System that we'll burn
onto some media disk.
https://riptutorial.com/ 3
Keeping Ubuntu and your packages up to date
Once you installed Ubuntu, you might want to get the latest patches and updates. Using Ubuntu's
easy to use package manager Aptitude, the OS along with all future packages that is installed
using this manner can be kept up to date.
1. Download the latest package lists by refreshing information from the repositories: sudo apt-
get update
2. Then proceed to run the following command to review which packages can upgraded: sudo
apt-get upgrade
3. Assuming you are satisfied with the lists of packages that can be upgraded, enter y to start
the installation process.
Also you could just hit enter, when presented with a choice the capitalized choice is the default,
and is selected if you hit enter and type nothing.
https://riptutorial.com/ 4
Read Getting started with Ubuntu online: https://riptutorial.com/ubuntu/topic/848/getting-started-
with-ubuntu
https://riptutorial.com/ 5
Chapter 2: Apache Server
Examples
Php 5.6 with Apache 2 Server on Ubuntu 16.04
This tutorial will guide you through the process from scratch. Please note some preliminary notes
about this particular setup, useful in case that you already have some requested package:
If you need to disable php 7.0 (or any different version) before proceeding, do the following:
a2dismod php7.0
a2enmod php5.6
If you are installing it under a virtual machine on VMware, please do the following:
Now Apache is installed and configured for php. Try to open a Browser and type localhost, it
should display the test page for Apache.
And edit as following, uncommenting and editing with the timezone that you prefer:
https://riptutorial.com/ 6
date.timezone = Europe/Rome
Extra step 1
If you are installing a tarball (tar.gz) on Apache, unzip it into /var/www/html (it's the default root
location)
Extra step 2
Please note that you may also need to change permissions to www-data, because default
permissions are to root and this can give some writing issues.
https://riptutorial.com/ 7
Chapter 3: Basic Terminal commands
Remarks
How to exract tar.gz/bz2/tbz files :
• v: This option will list all of the files one by one in the archive. The “v” stands for “verbose.”
• z: The z option is very important and tells the tar command to uncompress the file (gzip).
• f: This options tells tar that you are going to give it a file name to work with.
The major difference between these two is that the z option has been replaced by the j option.
Examples
Changing password of current user
sudo passwd
Note: By default, the keys you press at a command-line password prompt are not displayed at all.
They are, however, still registered.
https://riptutorial.com/ 8
Adding new user
adduser command adds a user to the system. In order to add a new user type:
example:
After typing the above command, you will be prompted to enter details about the new user, such
as new password, user Full name, etc.
Below is the information that user will be asked to fill in order to add a new user:
!!
(read as bangbang) is a shortcut to repeat the last command entered in console. It is especially
useful to run previous command with some changes
adduser tom
Oh snap, what now? Well you could retype the command with sudo in front or you could try
sudo !!
This is especially useful if the command you just typed is especially long.
cd path/to/wrong/directory
With
https://riptutorial.com/ 9
!!:s/wrong/right/
Will do
cd path/to/right/directory
user@host:/$ ls
bin boot cdrom dev etc home initrd.img lib lib64 lost+found
media mnt opt proc root run sbin srv sys tmp usr var vmlinuz
ls prints folder structure in simple view, color coded by type. The Ubuntu default colors for ls are:
blue for directories, green for executable files, sky blue for linked files, yellow with a black
background for devices, pink for image files, and red for archive files.
user@host:/$ ls -la
total 104
drwxr-xr-x 23 root root 4096 јул 25 12:40 .
drwxr-xr-x 23 root root 4096 јул 25 12:40 ..
drwxr-xr-x 2 root root 4096 јул 25 12:42 bin
drwxr-xr-x 4 root root 4096 јул 25 12:42 boot
drwxrwxr-x 2 root root 4096 јул 25 12:38 cdrom
drwxr-xr-x 16 root root 4300 јул 30 12:18 dev
drwxr-xr-x 134 root root 12288 јул 30 12:18 etc
drwxr-xr-x 5 root root 4096 јул 25 12:50 home
lrwxrwxrwx 1 root root 33 јул 25 12:40 initrd.img -> boot/initrd.img-3.19.0-39-generic
drwxr-xr-x 23 root root 4096 јул 25 12:42 lib
drwxr-xr-x 2 root root 4096 дец 9 2015 lib64
drwx------ 2 root root 16384 јул 25 12:32 lost+found
drwxr-xr-x 3 root root 4096 јул 25 14:56 media
drwxr-xr-x 2 root root 4096 апр 11 2014 mnt
drwxr-xr-x 3 root root 4096 јул 25 13:37 opt
dr-xr-xr-x 227 root root 0 јул 30 12:18 proc
drwx------ 2 root root 4096 јул 25 13:06 root
drwxr-xr-x 23 root root 780 јул 31 14:30 run
drwxr-xr-x 2 root root 12288 јул 25 12:46 sbin
drwxr-xr-x 2 root root 4096 дец 8 2015 srv
dr-xr-xr-x 13 root root 0 јул 30 12:18 sys
drwxrwxrwt 8 root root 4096 јул 31 16:05 tmp
drwxr-xr-x 10 root root 4096 дец 8 2015 usr
drwxr-xr-x 13 root root 4096 дец 9 2015 var
lrwxrwxrwx 1 root root 30 јул 25 12:40 vmlinuz -> boot/vmlinuz-3.19.0-39-generic
Another shortcut for ls -la is ll. However, this is not a builtin command. Rather its an alias
common in ubuntu systems, in full its ls -laF. The alias will give you the same output as ls -la,
but with additional slash (/) at the end of each folder, to help you with easier folder identification.
The ll alias can be viewed in full by typing alias ll. As illustrated below. If the alias is not set then
https://riptutorial.com/ 10
the command will give an error.
vagrant@host ~ ->>
08:05 AM Mon Sep 12$ alias ll
alias ll='ls -alF'
Restart Ubuntu
You can restart ubuntu from command line. Below is example of restarting ubuntu immediately.
sudo reboot
Another commands with same results are sudo shutdown -r now and sudo init 6.
Usage:
This command will install two new apps: deluge and openssh-server. You can install as many
apps as you want in only one line of commands.
Result is the same, but interaction with users is different from previous command. apt is designed
for end-users (human) and it's output may be changed between versions.
https://riptutorial.com/ 11
libssh2-1 libtar0 libupnp6 libusageenvironment1 libva-x11-1 libvcdinfo0
libvlc5 libvlccore7 libxcb-composite0 libxcb-keysyms1 libxcb-randr0
libxcb-xv0 vlc-data vlc-nox vlc-plugin-notify vlc-plugin-pulse
Suggested packages:
firmware-crystalhd freerdp-x11 gnutls-bin videolan-doc
Recommended packages:
libdvdcss2
The following NEW packages will be installed:
libbasicusageenvironment0 libcddb2 libcrystalhd3 libdvbpsi8 libebml4
libfreerdp1 libgnutls28 libgroupsock1 libhogweed2 libiso9660-8
liblivemedia23 libmatroska6 libproxy-tools libresid-builder0c2a libsidplay2
libssh2-1 libtar0 libupnp6 libusageenvironment1 libva-x11-1 libvcdinfo0
libvlc5 libvlccore7 libxcb-composite0 libxcb-keysyms1 libxcb-randr0
libxcb-xv0 vlc vlc-data vlc-nox vlc-plugin-notify vlc-plugin-pulse
0 upgraded, 32 newly installed, 0 to remove and 308 not upgraded.
Need to get 10,5 MB of archives.
After this operation, 51,7 MB of additional disk space will be used.
Do you want to continue? [Y/n]
DPKG
dpkgstands for Debian Package. This is basic, low-level package installer for Debian and other
Debian derivatives. dpkg have many options, but we are interested in -i, which stands for install.
If you get an error while installing .deb package, in most cases you don't have some
dependencies. To get rid of this error and install app correctly, run sudo apt-get -f install without
any other parameter. This will search for dependencies and install them before .deb. Installation
will continue and app will be installed.
Using Ubuntu you have different ways to read a text file, all similar but useful in different context.
cat
This is the simplest way to read a text file; it simply output the file content inside the terminal. Be
careful: if the file is huge, it could take some time to complete the printing process! If you need to
stop it, you can always press CTRL+C. Note that if you need to navigate through the document, you
need to scroll the terminal output.
cat file_name.txt
more
An improved version of cat. If your file is longer than the display of the terminal, you can simply
type
https://riptutorial.com/ 12
more file_name.txt
and you'll have a downwards scrolling display of text, in which you can move down by pressing
ENTER.
less
This is the more command with some enhancements, and is typically a better choice than cat for
reading medium to big documents. It opens file showing them from the beginning, allowing to
scroll up/down/right/left using arrows.
less file_name.txt
Once the document is open, you can type some commands to enable some useful features, such
as:
• q:
close immediately the opened file.
• /word: search 'word' inside the document. Pressing n you can go to the following occurrence
of 'word'.
• ENTER: scrolls down of a single line.
• r: repaints the file content, if it's changing while reading.
tail
This software shows only the last part of the file. It's useful if you need to read just a few lines in
the end of a very big document.
tail file_name.txt
The above command will show last 10 lines(default) of the file. To read last 3 lines, we need to
write:
tail -3 file_name.txt
There's another use case where this command is extremely useful. Imagine to have a empty
document, that is filled while you are watching it; if you want to see new lines in real time while
they are written to the file without reopening it, just open the file with the -f option. It's really useful
if you are watching some logs, for example.
tail -f file_name.txt
head
This command does the opposite task of tail. For example the following command will show the
https://riptutorial.com/ 13
first 15 lines of the file file_name.txt.
tailf
This is an alternative for tail -f filename .It follows the file changes as they occur and shows you
the output.
vim
Some of us like vi, some others like vim. This is not just for reading files, you can also edit them!
Now let's see only some features that regards reading documents. Please note that vim offers
syntax highlighting.
vim file_name.txt
Once the file is opened, be careful! Don't start typing, or you will mess everything up! In fact, even
if you can see the cursor, you have to press i to start typing and ESC after you finished typing. By
the way, now I'm going to showing you some useful commands that concern reading (not writing):
• : : you need to type colon before inserting each of the following commands!
• q! : exit from the file without asking a confirm. It's the same as q if you didn't edit the text.
• /word : search for 'word' inside the document.
• 230 : goes to line '230'.
Tip: a shortcut to insert a colon and then type wq! for writing edits to file and quit without asking a
confirm, you can hold down SHIFT and press twice z.
If you know you need a packet <packet>, but you don't know the exact name <packet-exact-
name>, instead of searching with Google try with the following:
This will return you a list of packets name with a description. Once you have identified the exact
packet name <packet-exact-name> install it normally:
If you are running a command that returns hundreds of lines, but your interest is just on the lines
that contains the word <word>, you should definitely use grep! For example try running:
https://riptutorial.com/ 14
ifconfig -a
Check the output, that could be only a few lines or quite long, if you have a server with multiple
network interfaces. To show (for example purpose) only the lines that contain 'HWaddr', try using
grep:
Now the output should be much shorter! Generally speaking, you could use grep in the following
way:
Use the tar (tape archive) command to compress your files and folders. It is similar to creating .ZIP
files in Windows environment.
https://riptutorial.com/ 15
Chapter 4: Networking
Examples
Set proxy from CLI
http_proxy=http://<proxy_server>:<port>/
https_proxy=http://<proxy_server>:<port>/
ftp_proxy=http://<proxy_server>:<port>/
Then press ESC, enter : and write wq! for save and exit from vim.
If you need to use wget, add the same three rows to (eventually uncommenting them inside the
file):
ifconfig
If you want to show also network interfaces that are down, type:
ifconfig -a
You could use ethtool, but they are not going to be reboot persistent. If you want to achieve this,
edit the following file:
auto <interface_name>
iface <interface_name> inet static
address <ip_address>
netmask <netmask>
https://riptutorial.com/ 16
network <network>
gateway <gateway>
dns_nameservers <server_1> <server_2> <server_n>
dns_naesearch <server_name>
https://riptutorial.com/ 17
Chapter 5: Set up SSL
Remarks
a2ensite - a script that enables the specified site (which contains a block) within the apache2
configuration by creating symlinks within /etc/apache2/sites-enabled
apache2 - popular web server. Alternative web servers are tomcat, nginx, etc.
openssl - SSL works by using a private key to encrypt data transferred over an SSL-enabled
connection, thus thwarting eavesdropping of information. Use openssl to generate keys and
certificates.
Examples
Set up ssl for local testing in apache
Optional (but a good idea): Create a directory that will contain our new certificate files:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
/etc/apache2/ssl/your_domain.key -out /etc/apache2/ssl/your_domain.crt
You will be asked a series of questions for your security certificate. Answer each one as you are
prompted, but with your own company's information. Here is an example:
https://riptutorial.com/ 18
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Cool Company
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:test_domain.com
Email Address []:my_email@test_domain.com
Configure your virtual host by adding your server details and certificate locations to the default-
ssl.conf file:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin [email protected]
ServerName your_domain.com
ServerAlias www.your_domain.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/your_domain.crt
SSLCertificateKeyFile /etc/apache2/ssl/your_domain.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /var/www/html>
SSLOptions +StdEnvVars
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
Save your changes and enter the following to enable your new ssl configuration:
https://riptutorial.com/ 19
Chapter 6: Software Installation
Syntax
• sudo apt-get install <package_name>
Parameters
Command Description
install This option is followed by one or more packages desired for installation.
remove Identical to install except that packages are removed instead of installed.
------ ------
Options Description
-y, --yes, -- Automatic yes to prompts. Assume "yes" as answer to all prompts and run
assume-yes non-interactively.
Examples
Install software using APT
Installing software via APT (Advanced Package Tool) also know as 'apt-get'. To install Mozilla
Firefox:
https://riptutorial.com/ 20
Software will be downloaded and installed.
Listing... Done
accountsservice/trusty-updates,now 0.6.35-0ubuntu7.3 i386 [installed]
acl/trusty,now 2.2.52-1 i386 [installed,automatic]
acpid/trusty,now 1:2.0.21-1ubuntu2 i386 [installed]
adduser/trusty,now 3.113+nmu3ubuntu3 all [installed]
apparmor/trusty-updates,trusty-security,now 2.10.95-0ubuntu2.6~14.04.1 i386 [installed]
apport/trusty-security,now 2.14.1-0ubuntu3.23 all [installed,upgradable to: 2.14.1-
0ubuntu3.24]
apport-symptoms/trusty,now 0.20 all [installed]
apt/trusty-updates,trusty-security,now 1.0.1ubuntu2.17 i386 [installed]
apt-transport-https/trusty-updates,trusty-security,now 1.0.1ubuntu2.17 i386 [installed]
apt-utils/trusty-updates,trusty-security,now 1.0.1ubuntu2.17 i386 [installed]
apt-xapian-index/trusty,now 0.45ubuntu4 all [installed]
aptitude/trusty,now 0.6.8.2-1ubuntu4 i386 [installed]
https://riptutorial.com/ 21
Chapter 7: Support lifespan
Remarks
New versions of Ubuntu are released by Canonical every 6 months. Every two years, the release
is a Long Term Support version.
Support lifespan
• Updates for potential security problems and bugs (not new versions of software)
• Availability of commercial support contracts from Canonical
• Support by Landscape, Canonical's enterprise oriented server management tool set.
Examples
Currently supported releases
The table shows a list of currently supported release showing both original distribution releases
(e.g. Ubuntu 14.04) and point releases (e.g. 14.04.3). The Ubuntu versions which are still
supported will be delivered security updates.
Point releases include support for new hardware as well as rolling up all the updates published in
that series to date. So a fresh install of a point release will work on newer hardware and will also
not require a big download of additional updates.
Ubuntu 16.04 LTS Xenial Xerus April 21, 2016 April 2021
Ubuntu 14.04.2 LTS Trusty Tahr February 20, 2015 August 2016
Ubuntu 14.04.1 LTS Trusty Tahr July 24, 2014 April 2019
https://riptutorial.com/ 22
Version Code name Release date End of life date
https://riptutorial.com/ 23
Credits
S.
Chapters Contributors
No
Getting started with Anagh Hegde, Community, edwinksl, hellyale, James Wong,
1
Ubuntu karel, kelvinelove, kzh, Nicholas Qiao
https://riptutorial.com/ 24