Odoo 11 Development Essentials(Third Edition)
上QQ阅读APP看书,第一时间看更新

Installing Odoo from source

Ready-to-install Odoo packages can be found at https://nightly.odoo.com, available as Windows (.exe), Debian (.deb), CentOS (.rpm), and source code tarballs (.tar.gz).

As developers, we will prefer installing them directly from the GitHub repository. This will end up giving us more control over versions and updates.

Odoo is built using the Python programming language, and it uses the PostgreSQL database for data storage; these are the two main requirements of an Odoo host. To run Odoo from the source, we will first need to install the Python libraries it depends on. The Odoo source code can then be downloaded from GitHub. While we can download a ZIP file or tarball, we will see that it's better if we get the sources using the Git version control application; it'll help us to have it installed on our Odoo host as well.

To keep things tidy, let's work in a /odoo-dev directory inside our home directory.

Throughout the book, we will assume that /odoo-dev is the directory where your Odoo server is installed.

First, make sure you are logged in as the user we created here or during the installation process, not as the root. Assuming your user is odoo, confirm it with the following command:

$ whoami
odoo
$ echo $HOME
/home/odoo

Now we are ready, we start by installing some basic dependencies needed by Odoo:

$ sudo apt-get update
$ sudo apt-get upgrade $ sudo apt-get install python3-dev python3-pip # Python 3 for dev
$ sudo apt-get install wkhtmltopdf # For report printing
$ sudo apt-get install git # Install Git $ sudo apt-get install npm # Install NodeJs and its package manager $ sudo ln -s /usr/bin/nodejs /usr/bin/node # node runs nodejs $ sudo npm install -g less less-plugin-clean-css # Install less

Starting from version 9.0, the Odoo web client requires the less CSS preprocessor to be installed in the system in order for web pages to be rendered correctly. To install this, we need Node.js and npm.

Previous Odoo versions only supported Python 2.7, but starting from version 11.0 Odoo runs on Python 3.5 or later. This is the primary Python version supported. It should still work with Python 2.7, but this is not guaranteed to hold true in the future.

Be aware that your operating system can have both Python versions installed, but the python and pip commands by default point to Python 2.7. Both installations will have their own installed package index, so if you are missing some Python library, make sure that you are using python3 and pip3 commands.

To install Odoo from the source, we should follow these steps:

  1. Clone the Git repository.
  2. Install Odoo dependencies.
  3. Install the PostgreSQL database.

We start by cloning the Odoo source code directly from GitHub:

$ mkdir ~/odoo-dev  # Create a directory to work in
$ cd ~/odoo-dev  # Go into our work directory
$ git clone https://github.com/odoo/odoo.git -b 11.0 --depth=1  # Get Odoo sources

At the end, Odoo should be ready to use. The ~ symbol is a shortcut for our home directory (for example, /home/odoo). The -b 11.0 option tells Git to explicitly download the 11.0 branch of Odoo. At the time of writing, this is redundant since 11.0 is the default branch; however, this may change, so it may make the script future-proof. The --depth=1 option tells Git to download only the last revision, instead of the full change history, making the download smaller and faster.

In previous editions, the Odoo source code included a utility script, inside the odoo/setup/ directory, to help us install the required dependencies in a Debian/Ubuntu system. As of Odoo 11, this script is not available.

Odoo is a Python application, depending on other Python packages installable using pip. Some of these packages require some system packages to be installed. To install all that is needed, we can use:

$ sudo apt-get install libxml2-dev libxslt1-dev libevent-dev \
libpq-dev libjpeg-dev poppler-utils # Odoo system dependencies
$ sudo apt-get install libldap2-dev libsasl2-dev # for LDAP
$ pip3 install -r ~/odoo-dev/odoo/requirements.txt

Alternatively, we could have installed the system packaged versions of these libraries, such as python3-lxml, using the apt-get package manager. The list of dependencies used can be found in the ./odoo/debian/control file.

The correct dependency installation may vary depending on your operating system and on the Odoo version you are installing. If you have trouble with any of the previous steps, make sure you check the official documentation at https://www.odoo.com/documentation/11.0/setup/install.html. Instructions for previous editions are also available there.

We still need to install the PostgreSQL database, required to run Odoo:

$ sudo apt-get install postgresql  # Install PostgreSQL
$ sudo su -c "createuser -s $(whoami)" postgres # Create db superuser

The last command creates a PostgreSQL user for the current system user. We need that so that we can create and drop the databases to be used by our Odoo instances.

Now, we can start the Odoo server instance by running:

$ ~/odoo-dev/odoo/odoo-bin
Since Odoo 10.0, the server is started using the ./odoo-bin executable. In former Odoo versions, the ./odoo.py script was used instead.

By default, Odoo instances listen on port 8069, so if we point a browser to http://<server-address>:8069, we will reach these instances. When we access it for the first time, it shows us an assistant to create a new database, as shown in the following screenshot:

As a developer, we will need to work with several databases, so it's more convenient to create them from the command line, and we will learn how to do this. Now, press Ctrl + C in the terminal to stop the Odoo server and get back to the command prompt.