reset password

Set Up Ubuntu 18.04

This guide describes how to install and configure commonly used software on Ubuntu 18.04.

Install Ubuntu

Download and install Ubuntu Server 18.04 or Ubuntu Desktop 18.04.

Starting from 18.04.1, Ubuntu Server doesn't include the "Universe" repositories where lots of useful software are hosted. Add them back by:

> sudo add-apt-repository universe

After installation, run the following commands to update the software packages:

> sudo apt update
> sudo apt upgrade

Then install some commonly used tools:

> sudo apt install mailutils mutt curl vim nmap git build-essential

During installation, when you are asked to select mail server configuration type, choose "Internet Site".

Configure Auto Update

unattended-upgrades should already be installed, but if not, install it first:

> sudo apt install unattended-upgrades

Edit /etc/apt/apt.conf.d/50unattended-upgrades to enable the following:

  • Install non-security updates
  • Email notification after upgrade
  • Auto remove unused kernel packages and dependencies
  • Auto reboot if a reboot is required after upgrade

Then

> sudo service unattended-upgrades restart

Nginx

For HTTP server I recommend Nginx over Apache as Nginx is not only faster, but for common setups Nginx configuration is also easier.

> sudo apt install nginx

Please check out Nginx Configuration on how to configure Nginx for various setups.

Java, Maven, and Tomcat

For Ubuntu Server, install openjdk-11-jdk-headless, and for Ubuntu Desktop, install openjdk-11-jdk, e.g.

> sudo apt install openjdk-11-jdk-headless

Then install Maven and Tomcat:

> sudo apt install maven tomcat8

Node.js 12 and NPM Global Packages

We want the most recent LTS release, which is 12 at the moment:

> curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
> sudo apt install -y nodejs

Using sudo to install NPM global package seems to be discouraged. The NPM documentation recommends using a version manager, but I feel that changing NPM's default directory (the second option in the documentation) is better because it keeps the same command line syntax as on Windows, and it's one less tool to learn or use. So:

> mkdir ~/.npm-global
> npm config set prefix '~/.npm-global'

Edit .profile file so the PATH environment variable looks like the following:

PATH=$PATH:$HOME/.npm-global/bin

then

> source ~/.profile

MySQL

There are two versions of MySQL: one distributed with Ubuntu and one distributed by MySQL.com. We'll use the second one as it's more up to date.

First download and install the package from MySQL.com that sets up the apt repository:

> wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
> sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
> sudo apt update

You will be asked to to choose MySQL server version and other components, and you can simply leave everything to default.

Then install MySQL server:

> sudo apt install mysql-server

After MySQL server is installed, run the following command to create a more secure setup:

> sudo mysql_secure_installation

You will be asked a number of questions. Here are my suggestions for the answers:

  • VALIDATE PASSWORD plugin: No
  • Change root password: No
  • Remove anonymous user: Yes
  • Disallow root login remotely: Yes
  • Remove test database: Yes
  • Reload privilege tables: Yes

After that you may want to create a non-root user for regular database usage. For example:

> mysql -u root -p
mysql> create database cysun;
mysql> create user 'cysun'@'%' identified by 'abcd';
mysql> grant all privileges on *.* to 'cysun'@'%' with grant option;
mysql> quit

The MySQL JDBC driver has become increasingly picky about various things, and among them the timezone of the server. Here's the fix:

First, set the correct timezone using the command timedatectl.

Then populate MySQL's timezone tables with the following command:

> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

And finally, edit  /etc/mysql/mysql.conf.d/mysqld.cnf and add a default-time-zone system variable, e.g.

default-time-zone = 'America/Los_Angeles'

PostgreSQL

> sudo apt-get install postgresql

Again, create a regular user:

> sudo -u postgres psql template1
psql> create user cysun with createdb password 'abcd';
psql> create database cysun with owner=cysun;
psql> \q

Leave out the createdb option in the CREATE USER statement if you do not want to grant the user the privilege to create databases.

MongoDB

There are two versions of MongoDB: one distributed with Ubuntu and one distributed by mongodb.org. We'll use the second one as it's more up to date.

> sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
> echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
> sudo apt update
> sudo apt install mongodb-org

After installing the packages, start the mongod service and set the service to autostart after reboot:

> sudo service mongod start
> sudo systemctl enable mongod.service

MongoDB shows a few startup warnings/messages when a mongo client is connected to the server, and these warnings/messages can be a bit annoying for a single-user development setup. You can edit /etc/mongod.conf to disable two of them:

security:
  authorization: disabled
cloud:
  monitoring:
    free:
      state: off

If you are not using XFS as the file system, there's also a warning about performance, and that warning cannot be disabled in configuration.

To convert a standalone MongoDB server into a replica set (for example, if you want to take advantage of the new multi-document transaction support), add the following to /etc/mongod.conf:

replication:
  replSetName: rs
  oplogSizeMB: 100

Then restart the mongod service, connect to server, and run rs.initiate():

> sudo service mongod restart
> mongo
mongo> rs.initiate() 
rs:PRIMARY> quit()

Subversion

> sudo apt-get install subversion xinetd

Create /etc/xinetd.d/svn with the following content:

service svn
{
        disable                 = no
        port                    = 3690
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = cysun
        server                  = /usr/bin/svnserve
        server_args             = -i -r /home/cysun/subversion
}

then restart xinetd:

> sudo /etc/init.d/xinetd restart

Email

The email server postfix should have already been installed after you installed the mailutils package, which allows you to send and receive emails.

You can set up aliases that allow one account to have multiple email addresses by editing /etc/aliases, then run the following command to inform postfix about the aliases:

> sudo newaliases

Another useful thing to do during development is to set up a catch-all email address to receive all the testing emails:

First edit /etc/postfix/main.cf to add the following line:

virtual_alias_maps = hash:/etc/postfix/virtual

Then create the file /etc/postfix/virtual with the following line (replace cysun with the account that serves as the catch-call address):

@localhost.localdomain  cysun

Then make postfix aware of the changes:

> sudo postmap /etc/postfix/virtual
> sudo service postfix reload

Now you can create many local email addresses (e.g. test1@localhost.localdomain, test2@localhost.localdomain and so on), and use one account to get all the emails.

.NET Core SDK

> wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
> sudo dpkg -i packages-microsoft-prod.deb
> sudo apt install apt-transport-https
> sudo apt update
> sudo apt install dotnet-sdk-3.1

Desktop Software

Ubuntu Display Settings only have two scaling options: 100% and 200%. On my laptops the fonts are too small for 100% and too large for 200%. Install gnome-tweaks as follows:

> sudo apt install gnome-tweaks

Then you can tweak Scaling Factor under Fonts in gnome-tweaks.

To install Google Chrome, first create a file /etc/apt/sources.list.d/google-chrome.list with the following content:

deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

Download and add Google's signing key:

> wget https://dl.google.com/linux/linux_signing_key.pub
> sudo apt-key add linux_signing_key.pub

Then install Chrome:

> sudo apt update
> sudo apt install google-chrome-stable

MongoDB Compass can be downloaded from here -- note that you should choose the Community Edition from the version dropdown list. After the .deb package is downloaded, double click on it to install.

If you use Visual Studio Code on Ubuntu Desktop for Angular development, you may run into an error that says "Visual Studio Code is unable to watch for file changes in this large workspace". The solution is to increase the system setting max_user_watches as follows:

> echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

User Management

Function Command Example
Add a user sudo adduser <username> sudo adduser cysun
Add a user to a groupo sudo usermod -aG <group> <username> sudo usermod -aG sudo cysun
List the groups a user belongs to groups <username> groups cysun
Remove a user sudo deluser --remove-home <username> sudo deluser --remove-home cysun

 

This page has been viewed 31415 times.