NetBox is four moving parts: a PostgreSQL database, a Redis cache, the Django application served by gunicorn, and a web server in front of it for HTTPS. We install them in that order, checking each one before moving on.
Before you start
$sudo apt update && sudo apt upgrade -yPostgreSQL
$sudo apt install -y postgresql$psql --versionpsql (PostgreSQL) 16.x
Create the database and its owner:
$sudo -u postgres psql -c "CREATE DATABASE netbox;"$sudo -u postgres psql -c "CREATE USER netbox WITH PASSWORD '';"$sudo -u postgres psql -c "ALTER DATABASE netbox OWNER TO netbox;"$sudo -u postgres psql -d netbox -c "GRANT CREATE ON SCHEMA public TO netbox;"$psql --username netbox --password --host localhost netbox -c '\conninfo'You are connected to database "netbox" as user "netbox" on host "localhost"
Redis
$sudo apt install -y redis-server$redis-cli pingPONG
Install NetBox
$sudo apt install -y git python3 python3-pip python3-venv python3-dev build-essential \$ libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev$python3 -VPython 3.12.x
$sudo mkdir -p $sudo git clone -b --depth 1 https://github.com/netbox-community/netbox.git $sudo adduser --system --group netbox$sudo chown --recursive netbox /netbox/media/ /netbox/reports/ /netbox/scripts/Configuration
$sudo cp /netbox/netbox/configuration_example.py /netbox/netbox/configuration.py$python3 /netbox/generate_secret_key.pyEdit configuration.py and set these values (paste the key printed above into SECRET_KEY):
ALLOWED_HOSTS = ['']DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'netbox', 'USER': 'netbox', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', 'CONN_MAX_AGE': 300, }}REDIS = { 'tasks': {'HOST': 'localhost', 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 0, 'SSL': False}, 'caching': {'HOST': 'localhost', 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 1, 'SSL': False},}SECRET_KEY = 'paste-the-generated-key-here'Run the upgrade script
$sudo /upgrade.sh$sudo /venv/bin/python /netbox/manage.py checkSystem check identified no issues
Create the first administrator:
$sudo /venv/bin/python /netbox/manage.py createsuperuser$sudo ln -s /contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeepinggunicorn and systemd
$sudo cp /contrib/gunicorn.py /gunicorn.py$sudo cp -v /contrib/*.service /etc/systemd/system/$sudo systemctl daemon-reload$sudo systemctl enable --now netbox netbox-rq$systemctl is-active netbox netbox-rqactive active
$curl -sI http://127.0.0.1:8001/ | head -1HTTP/1.1 200 OK
Web server and HTTPS
$sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \$ -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt \$ -subj "/CN="$sudo apt install -y nginx$sudo cp /contrib/nginx.conf /etc/nginx/sites-available/netbox$sudo sed -i 's/netbox.example.com//' /etc/nginx/sites-available/netbox$sudo rm -f /etc/nginx/sites-enabled/default$sudo ln -sf /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox$sudo nginx -t && sudo systemctl restart nginx$curl -skI https:/// | head -1HTTP/2 200
Done
Open https:/// and log in with the administrator you created. The next page of this series adds users and permissions, plugins and the settings you will want before opening NetBox to your team.