I will be installing on Raspbien 12 (Bookworm). Additionally, the installation will be done manually, using a Python venv - the Snap Store doesn't install the latest version of Octoprint.
Install Python pip
and venv
apt install -y python3 python3-pip python3-dev python3-setuptools python3-venv build-essential && \
python3 --version && \
which python3
Create a new user to run OctoPrint with a home directory /opt/octoprint
mkdir /opt/octoprint && \
adduser --disabled-password --home /opt/octoprint octoprint && \
chown -R octoprint:octoprint /opt/octoprint/
Add the new user to the tty
, dialout
and video
groups to ensure it can communicate with the printer correctly.
usermod -a -G tty octoprint && \
usermod -a -G dialout octoprint && \
usermod -a -G video octoprint
Login as the new octoprint user
su - octoprint
Setup a new venv
for this instance of OctoPrint to run inside of. If you have multiple printers and need multiple instances of OctoPrint, repeat this process with a new directory for each instance.
The last command with activate the new venv
for you to work inside of.
mkdir octoprint_1 && \
python3 -m venv ./octoprint_1/venv && \
source octoprint_1/venv/bin/activate
Upgrade pip
and install OctoPrint
pip install --upgrade pip && \
pip install octoprint
Exit the VE
deactivate
Login as root again
Create a new service file
bash -c "cat > /etc/systemd/system/octoprint@.service" <<'EOF'
[Unit]
Description=OctoPrint (instance %i) - Open Source Printing Interface for 3D Printers
Documentation=https://docs.octoprint.org
After=network.target
[Service]
User=octoprint
Group=octoprint
Environment=HOME=/opt/octoprint
WorkingDirectory=/opt/octoprint/octoprint_%i
ExecStart=/opt/octoprint/octoprint_%i/venv/bin/python3 /opt/octoprint/octoprint_%i/venv/bin/octoprint --basedir /opt/octoprint/octoprint_%i --config /opt/octoprint/octoprint_%i/config.yaml --port 500%i serve
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
EOF
The %i
will be replaced with whatever is behind the @
when running systemctl enable octoprint@1.service
. This will allow for the multiple instances discussed earlier.
Reload systemd and enable the new service
systemctl daemon-reload && \
systemctl enable --now octoprint@1.service && \
systemctl status octoprint@1.service
OctoPrint should now be running on tcp/5001. If not, make sure to check your logs for any related issues.
Setup sudo to allow the octoprint user to restart the OctoPrint service
echo "octoprint ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart octoprint@[1-9].service" | tee /etc/sudoers.d/40-octoprint
Once you get to the “Server Commands” section, use the following command in the “Restart OctoPrint” field (use the corresponding instance number
/usr/bin/sudo /usr/bin/systemctl restart octoprint@1.service
The installation is now complete, navigate to http://[ip/hostname]:5001 in your browser to complete the setup wizard.