ERPGAP Blog / Setting Up Odoo on macOS Using Multipass
Setting Up Odoo on macOS Using Multipass

Setting Up Odoo on macOS Using Multipass


A Comprehensive Guide to Installing Odoo with Multipass on macOS

Introduction

Setting up Odoo on macOS can be a seamless process when using Multipass. This guide walks you through the steps to create and configure an instance, enable SSH access, configure VS Code, and install Odoo, ensuring a smooth setup for development purposes.

Discover Odoo

1. Creating an Instance with Multipass

Firsty, create a cloud-init file that will optimise the connection between your computer and the Odoo instance.

1.1 Cloud-Init Configuration

This is an important step if you are interested in enter into the VM using the SSH public key authentication. Otherwise you can skip to step 1.2.

  • Assuming you have already generated SSH keys on your macOS and they are in the ~/.ssh folder, copy the SSH Key:
cat ~/.ssh/id_rsa.pub

In case you need to create your ssh keys, find a tutorial here

  • Then, create a yaml file and save it in the .ssh folder:
cd ~/.ssh
touch cloud-init.yaml
  • Cloud-Init configuration can have multiple purposes and have plenty of setings to be used. This is a simple Cloud-Init configuration for setting up users and SSH keys:
users:
    - default
    - name: ubuntu
        sudo: ALL=(ALL) NOPASSWD:ALL
        ssh_authorized_keys: [paste your rsa public keys here]

For more information, refer to the 'Using Multipass with cloud-init'.

1.2 Create the VM

  • Now let's create a Multipass instance with a custom name, CPU allocation, disk space, RAM and Cloud-Init setings.     - If you skipped the step 1.1, then remove the cloud init command (--cloud-init ~/.ssh/cloud-init.yaml).
# message: 
Launched: odoo-dev

1.2.1 Managing the Instance

You can start, open a shell prompt inside, and stop the instance using the following commands:

multipass start odoo-dev
multipass stop odoo-dev
multipass shell odoo-dev
multipass stop --all
multipass list

We suggest to stop all the instances and reboot your computer before proceeding to the next seteps.

For more information, refer to the Multipass documentation.

2. Configuring VS Code to Access the Instance

  • Ensure you have the Remote-SSH extension installed in VS Code.
  • Open the command palette (CMD + Shift + P), type ssh, and select Remote-SSH: Add New Host.
  • Follow the prompts to configure the SSH settings:
Host odoo-dev
    HostName <IP address visible using the command 'multipass list' after starting the instance>
    User ubuntu
    ForwardAgent yes

Now, you can access the instance from VS Code.

3. Odoo Installation

  • Install the following dependencies:
sudo apt install git python3-virtualenv postgresql nginx

Diferent Python versions are recomended to different Odoo versions. Ensure you install the correct Python versions compatible with your Odoo version. Since we will demonstrate with Odoo 17.0, Python 3.10 is the recomended version. You can check it here

  • Install Python 3.10 in your instance:
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10 python3.10-venv python3.10-dev

3.1 Clone Odoo Repositories

The organisation and folder names depends on each one method. For us this is the most productive and reproducible method to use.

  • Create necessary directories and clone the Odoo repositories.

Community Version

mkdir -p ~/git/odoo && cd ~/git/odoo
git clone --single-branch --branch 17.0 --depth 1 https://github.com/odoo/odoo.git 17.0

Enterprise Version

mkdir -p ~/git/oe && cd ~/git/oe
"Use the OE git access you may have"

Themes

mkdir -p ~/git/themes && cd ~/git/themes
git clone --single-branch --branch 17.0 --depth 1 https://github.com/odoo/design-themes.git 17.0

3.2 Create Virtual Environments

  • Create a generic virtual to start. We advise you to have one virtual envoirement per Odoo project.
#create a folder named 'envs' in the root
mkdir -p ~/envs && cd ~/envs
#create a virtual environment inside envs named '17.0'
python3.10 -m venv 17.0

3.3 Install Requirements

  • Activate the virtual environment and install the requirements.
source ~/envs/17.0/bin/activate
pip install -r ~/git/odoo/17.0/requirements.txt

If you encounter issues, refer to this guide for solutions.

4. Nginx Configuration

Configure Nginx to serve Odoo.

  • Access the nginx default file:
sudo -i
sudo nano /etc/nginx/sites-available/default
  • Paste the following configuration:
#odoo server
upstream odoo {
  server 127.0.0.1:8069;
}
upstream odoochat {
  server 127.0.0.1:8072;
}
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen 80;
  server_name localhost;
  proxy_read_timeout 720s;
  proxy_connect_timeout 720s;
  proxy_send_timeout 720s;

  # log
  access_log /var/log/nginx/odoo.access.log;
  error_log /var/log/nginx/odoo.error.log;

  # Redirect websocket requests to odoo gevent port
  location /websocket {
    proxy_pass http://odoochat;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    # proxy_cookie_flags session_id samesite=lax secure;  # requires nginx 1.19.8
  }

  # Redirect requests to odoo backend server
  location / {
    # Add Headers for odoo proxy mode
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_redirect off;
    proxy_pass http://odoo;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    # proxy_cookie_flags session_id samesite=lax secure;  # requires nginx 1.19.8
  }

  # common gzip
  gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}
  • Verify Configuration and Restart Nginx
nginx -t

You should see a message indicating the configuration is successful.

  • Then, restart the Nginx service:
sudo service nginx reload
logout

5. Database Preparation

5.1 Create PostgreSQL User and Database

  • Create a user with the same username as your Ubuntu instance:
sudo su - postgres
createuser --superuser ubuntu
psql -U postgres
  • Verify the user creation:
\du ubuntu
\q
  • Create a database for Odoo:
createdb odoo17
logout

6. Preparing Odoo

  • Activate the appropriate virtual environment and configure the Odoo addons path:
source ~/envs/17.0/bin/activate
~/git/odoo/17.0/odoo-bin -s --addons-path ~/git/oe/17.0/,~/git/odoo/17.0/odoo/addons,~/git/odoo/17.0/addons,~/git/themes/17.0
  • Install base Odoo model:
~/git/odoo/17.0/odoo-bin -d odoo17 -i base --db-filter ^odoo17$
  • Run Odoo
~/git/odoo/17.0/odoo-bin -d odoo17 --db-filter ^odoo17$
  • Access Odoo through a browser using your instance IP as URL

Discover Odoo

Conclusion

Setting up Odoo on macOS using Multipass is a straightforward process that can significantly enhance your development environment. By following these steps, you can efficiently configure and run Odoo, leveraging the power of Multipass for an isolated and controlled setup.

For more information or assistance, feel free to contact us.

Contact Us

Follow Us On Social Media

Stay connected with ERPGAP and follow us on this journey. You can view updates on LinkedIn and Twitter.


Other articles



How to Configure Stripe as a Payment Provider in Odoo Branches

How to Configure Stripe as a Payment Provider in Odoo Branches

What is a stable Odoo server?

What is a stable Odoo server?

Choosing the best way to host your Odoo server

Choosing the best way to host your Odoo server

About us

Odoo is a management software that fits all sizes. This software is for small, medium and large companies. Your company's information is all in one place. You don't have to go back and forth to check something. All apps have real-time access to your database.

Tags tags icon