How to Install Odoo 16 ERP Software on Ubuntu 22.04

Odoo (formerly known as OpenERP) is a self-hosted suite of over 10,000 open Odoo is a free and open-source ERP solution for multiple types of businesses. It provides customer relationship management (CRM), sales pipeline, project management, manufacturing, invoicing, accounting, eCommerce, and many more.

Odoo is one of the complete ERP solutions for your business. It comes with 30 core modules by default and provides more than 4500 community modules that can help your multiple businesses.

In this tutorial, we will the Odoo open-source ERP on the Ubuntu 22.04 server. We will install and configure the latest stable version of Odoo 16, set up the PostgreSQL database for Odoo, and lastly set up the Nginx as a reverse proxy for the Odoo application.

Prerequisites

To begin with this tutorial, you will need some following requirements:

  • An Ubuntu 22.04 server - This example uses an Ubuntu server with the hostname 'odoo-server'.
  • A non-root user with sudo root/administrator privileges - or you can also use the root user.
  • A domain name pointed to the server IP address - for production, you will need a domain name for the Odoo installation.

Installing Dependencies

To install Odoo, you will first need to install some package dependencies to your Ubuntu system. The Odoo ERP is a web application mainly written in Python, so you will also need to install some Python packages.

Before start installing packages, run the following apt command to update and refresh your package index.

sudo apt update

Next, install package dependencies for odoo via the following apt command. This installation will include the latest version of Python 3.10, build-essentials for compiling Python packages, and some libraries needed by odoo.

sudo apt install git wget python3 build-essential libzip-dev python3-dev libxslt1-dev python3-pip libldap2-dev python3-wheel libsasl2-dev python3-venv python3-setuptools node-less libjpeg-dev xfonts-75dpi xfonts-base libxrender1 libpq-dev libffi-dev fontconfig

When prompted, input y to confirm and press ENTER to proceed. And the installation will begin.

install dependencies

Once Python and other dependencies are installed, the next step is to install Node.js which will be used to generate static files, and install the wkhtmltopdf package for generating PDF reports.

Installing Nodejs

To install Odoo, you must ensure that Node.js is installed on your system. Node.js is used to generate static files for odoo web applications. In this step, you will install Node.js 16 from the third-party Nodesource repository.

Run the following command to download and set up the Nodesource repository for Node.js 16.

sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

This command will download and run the installer script, then the installer script will automatically set up the repository for Node.js, add the GPG key, and automatically update and refresh the package index on your system.

setup nodesource

Next, run the following apt command to install the Node.js package. When prompted, input y to confirm and press ENTER to proceed.

sudo apt install nodejs

install nodejs

Once Node.js is installed, run the following npm command to install the 'rtlcss' package.
The 'rtlcss' package is needed for odoo, especially if you are using the right-to-left user interface for specific languages such as Arabic and Hebrew.

sudo npm install -g rtlcss

Installing Wkhtmltopdf Application

The odoo open-source ERP required the wkhtmltopdf package to be installed. This package is needed for rendering HTML pages to PDF and various image formats via the Qt Webkit. The wkhtmltopdf package will be installed manually via the .deb package to the Ubuntu system.

Run the following command to download the .deb file of the Wkhtmltopdf package.

cd /tmp
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb

Install the Wkhtmltopdf package via the dpkg command below.

sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb

install wkhtmltopdf

If you get an error such as a missing package, fix it via the following apt command.

sudo apt install -f

After the Wkhtmltopdf is installed, you can verify the binary file Wkhtmltopdf package that is available by default on the '/usr/local/bin' directory. You should see two programs the 'wkhtmltopdf' and 'wkhtmltoimage'.

ls /usr/local/bin

Now run the following command to verify the $PATH environment variable and make sure the '/usr/local/bin' directory is available on the binary $PATH. Otherwise, the Wkhtmltopdf package will not work properly.

echo $PATH

Lastly, run the following command to ensure the binary path for the Wkhtmltopdf package is available. If the Wkhtmltopdf package is available, you should receive an output of the full path of the Wkhtmltopdf package.

which wkhtmltopdf
which wkhtmltoimage

setup wkhtmltopdf

Installing PostgreSQL Database Server

The odoo open-source ERP supports databases like MySQL, SQLite, and PostgreSQL. In this step, you will install and use PostgreSQL as the default database for your odoo installation. You will also be setting up the PostgreSQL role and making changes to the PostgreSQL configuration.

Run the following apt command to install the PostgreSQL database server. When prompted for confirmation, input y, and press ENTER.

sudo apt install postgresql

install postgresql

After PostgreSQL is installed, run the following command to verify the PostgreSQL and make sure the service is enabled and running.

sudo systemctl is-enabled postgresql
sudo systemctl status postgresql

In the following output, you can see the PostgreSQL service is enabled and will be run automatically at system startup. And the status of the PostgreSQL is running.

check postgresql service

Next, you will be creating a new role for the odoo. Run the following command to log in to the 'postgres' user and create a new role with the name 'odoo'.

su - postgres
createuser -sdP odoo

Input the password for the new role 'odoo' and repeat it.

Now, log in to the PostgreSQL shell via the psql command below.

psql

Run the following query to verify the list of the role on PostgreSQL and make sure the role 'odoo' is available.

\du

Now input '\q' to exit from the PostgreSQL shell. Then, type 'exit' to log out from the postgres user.

create postgresql role

Now after you have created a role for odoo, you will now set up authentication for the 'odoo' role.

Edit the PostgreSQL configuration '/etc/postgresql/14/main/pg_hba.conf' using the following nano editor.

sudo nano /etc/postgresql/14/main/pg_hba.conf

Add the following configuration to the file. With this, you will allow access to the PostgreSQL for the role 'odoo' with the password authentication 'scram-sha-256'.

host    all   odoo    127.0.0.1/32    scram-sha-256

Save the file and exit the editor when you are done.

Now run the following command to restart the PostgreSQL service and apply new changes.

sudo systemctl restart postgresql

Lastly, log in as the 'postgres' user and verify the 'odoo' role by logging into the PostgreSQL shell via the psql command as below.

su - postgres
psql -h 127.0.0.1 -U odoo -d postgres

After logging in, verify using the following query.

\conninfo

You should now see that you're connected to PostgreSQL using the role 'odoo'.

check postgresql role

At this point, the PostgreSQL database preparation for odoo is now finished. Next, you will start the odoo installation by downloading the source code and installing Python dependencies.

Downloading Odoo 16

For this demo, you will set up and run odoo v16 with the user 'odoo'. So now you will create a new Unix user 'odoo' and download the latest version of odoo 16 source code.

Run the following command to create a new user 'odoo'. In this example, the default home directory for the user 'odoo' would be '/opt/odoo' and the default shell is bash.

sudo adduser --system --group --home=/opt/odoo --shell=/bin/bash odoo

Now move the working directory to '/opt/odoo' and download the odoo source code via the following git command. In this example, you will install the odoo 16.

cd /opt/odoo
git clone https://github.com/odoo/odoo.git --depth 1 --branch 16.0 --single-branch odoo-server

You should now get the new directory 'odoo-server' inside the '/opt/odoo' directory.

Lastly, run the following command to change the ownership of the odoo source code to the user and group 'odoo'.

sudo chown -R odoo:odoo /opt/odoo/odoo-server

download odoo

After downloading the odoo source code, you will next start the installation of Python package dependencies for odoo.

Installing Python Dependencies for Odoo

In this step, you will set up the Python virtual environment for odoo and install Python dependencies via the pip3 command.

Move the working directory to '/opt/odoo/odoo-server' and create a new Python virtual environment 'venv' via the following command.

cd /opt/odoo/odoo-server
python3 -m venv venv

Next, activate the 'venv' Python virtual environment via the following command.

source venv/bin/activate

After you have activated the Python virtual environment, you will see that your current shell changed to like '(venv) root@hostname...'.

setup python venv

Now run the following pip3 command to install the Python package wheel and install odoo Python dependencies via the file requirements.txt.

pip3 install wheel
pip3 install -r requirements.txt

install dependnecies

After Python dependencies are installed, run the following command to exit from the Python 'venv' virtual environment.

deactivate

You have now downloaded the odoo source code and installed Python dependencies. Next, you will create a new configuration and directory for odoo installation.

Creating Odoo Configuration

After installed package dependencies for Odoo, you will next start creating configuration for odoo and setting up odoo as systemd service.

Create a new configuration file '/etc/odoo.conf' using the following nano editor.

sudo nano /etc/odoo.conf

Add the following configuration to the file. And make sure to change the 'admin_passwd' and details database user and password with your details.

[options]
; This is the password that allows database operations:
admin_passwd = adminpassodoo
db_host = 127.0.0.1
db_port = 5432
db_user = odoo
db_password = odoopass
addons_path = /opt/odoo/odoo-server/addons
xmlrpc_port = 8069
logfile = /var/log/odoo/odoo-server.log
log_level  = debug

Save the file and exit the editor.

Now, change the ownership of the odoo configuration file '/etc/odoo.conf' to the system user 'odoo'.

sudo chown odoo:odoo /etc/odoo.conf

Next, run the following command to create a new directory that will be used to store logs for odoo.

sudo mkdir /var/log/odoo

Then, change the ownership of the odoo log directory '/var/log/odoo' to the user 'odoo' and change the permission to 755.

sudo chown odoo:odoo /var/log/odoo 
sudo chmod 755 /var/log/odoo

create odoo configuration

Runnnig Odoo as Systemd Service

At this point, you can run odoo manually via the command line. To make it easier, you can run odoo as a systemd service. This allows you to manage odoo via the systemctl command.

You will now create a new systemd service file and run odoo as the systemd service.

To start, create a new systemd service file '/lib/systemd/system/odoo-server.service' using the following nano editor.

sudo nano /lib/systemd/system/odoo-server.service

Add the following configuration to the file.

[Unit]
Description=Odoo 16.0 Service
Requires=postgresql.service
After=network.target postgresql.service
 
[Service]
Type=simple
SyslogIdentifier=odoo
PermissionsStartOnly=true
User=odoo
Group=odoo
ExecStart=/opt/odoo/odoo-server/venv/bin/python3 /opt/odoo/odoo-server/odoo-bin -c /etc/odoo.conf
StandardOutput=journal+console
 
[Install]
WantedBy=multi-user.target

Save the file and exit the editor when you are done.

Next, reload the systemd manager to apply a new service file via the systemctl command below.

sudo systemctl daemon-reload

Start and enable the service 'odoo-server' using the following command.

sudo systemctl start odoo-server
sudo systemctl enable odoo-server

setup odoo service

Lastly, verify the odoo service to ensure the service is running.

sudo systemctl status odoo-server

You should receive the output of the service 'odoo-server' running.

check odoo service

Running Odoo with Nginx Reverse Proxy

The recommended way to deploy odoo on production is by using the reverse proxy. This allows you to run odoo only on the localhost and all client access will be handled by the reverse proxy.

In this step, you will install and set up the Nginx web server as a reverse proxy for the odoo web application. You will also have the odoo installation secured with SSL. So, before start configuring Nginx, ensure that you have the domain name pointed to the server IP address and generated SSL Letsencrypt.

First, modify the odoo configuration file '/etc/odoo.conf' using the following nano editor.

sudo nano /etc/odoo.conf

Add the following configuration to the file. This configuration will run odoo as the backend application that will be running on 127.0.0.1.

xmlrpc_interface = 127.0.0.1
proxy_mode = True

Save the file and exit the editor when you are done.

Now run the following command to restart the 'odoo-server' service and apply new changes.

sudo systemctl restart odoo-server

Now verify the 'odoo-server' service to ensure the service is running.

sudo systemctl status odoo-server

configure odoo

Next, you will now install and configure Nginx.

Run the following apt command to install the Nginx web server package. Input y when prompted and p