The following tutorial provides step-by-step instructions to install Lemmy, a link aggregator for the fediverse, on Ubuntu 22.04. It includes the installation of Lemmy backend, Lemmy UI (web frontend), and the configuration of a reverse proxy with TLS using Nginx.
You should be able to install Lemmy without any errors. If you have any, please let me know. I intend to extend this tutorial to Lemmy upgrades, migration and deletion, and thus update the official documentation.
Installation
Lemmy Backend
-
Install Rust by following the instructions on Rustup.
-
Install the dependencies required for image hosting with Pict-rs:
apt install ffmpeg exiftool libgexiv2-dev --no-install-recommends wget https://download.imagemagick.org/ImageMagick/download/binaries/magick sha256sum magick # Compare hash with the "message digest" on the official page mv magick /usr/bin/ chmod 755 /usr/bin/magick -
Compile and install Lemmy, and set up the database:
apt install pkg-config libssl-dev libpq-dev postgresql-15 postgresql-contrib-15 protobuf-compiler # Install the latest release. You can specify a version with --version. # The --locked argument uses the exact versions of dependencies specified in `cargo.lock` at release time. # Running it without the flag will use newer minor release versions of those dependencies, which are not always guaranteed to compile. # Remove the parameter `--features embed-pictrs` if you don't require image hosting. cargo install lemmy_server --root /usr/ --locked --features embed-pictrs # Replace db-passwd with a randomly generated password sudo -iu postgres psql -c "CREATE USER lemmy WITH PASSWORD 'db-passwd';" sudo -iu postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;" sudo -iu postgres psql -c "ALTER USER lemmy WITH SUPERUSER;" adduser lemmy --system --disabled-login --no-create-home --group -
Configure the Lemmy backend by creating the minimal Lemmy config file at
/etc/lemmy/lemmy.hjson# Put your db-passwd from above { database: { password: "db-passwd" }, # Replace with your domain hostname: "example.com", bind: "127.0.0.1", federation: { enabled: true }, # Remove this block if you don't require image hosting pictrs: { url: "http://localhost:8080/" } }Run
chown lemmy:lemmy /etc/lemmy/ -Rto set the correct owner. -
Create a systemd unit file for Lemmy to automatically start and stop:
# Create /etc/systemd/system/lemmy.service [Unit] Description=Lemmy - A link aggregator for the fediverse After=network.target [Service] User=lemmy ExecStart=/usr/bin/lemmy_server Environment=LEMMY_CONFIG_LOCATION=/etc/lemmy/lemmy.hjson # Remove these two lines if you don't need Pict-rs Environment=PICTRS_PATH=/var/lib/pictrs Environment=PICTRS_ADDR=127.0.0.1:8080 Restart=on-failure # Hardening ProtectSystem=yes PrivateTmp=true MemoryDenyWriteExecute=true NoNewPrivileges=true [Install] WantedBy=multi-user.targetRun
systemctl enable lemmyandsystemctl start lemmyto enable and start the service. -
Verify the Lemmy installation by checking the logs:
journalctl -u lemmyThe logs should show “Starting http server at 127.0.0.1:8536”. You can also run
curl localhost:8536/api/{version}/siteto check the response. -
For Pict-rs, run
curl 127.0.0.1:8080and ensure that it outputs nothing, particularly no errors.
Install Lemmy UI (Web Frontend)
-
Install dependencies:
# Install Node.js and Yarn from external repositories curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt install nodejs yarn -
Clone the Lemmy UI Git repository, checkout the desired version, and compile it:
mkdir /var/lib/lemmy-ui cd /var/lib/lemmy-ui chown lemmy:lemmy . sudo -u lemmy bash git clone https://github.com/LemmyNet/lemmy-ui.git --recursive . git checkout 0.17.4 # Replace with the version you want to install yarn install --pure-lockfile yarn build:prod exit -
Create a systemd unit file for Lemmy UI:
# Create /etc/systemd/system/lemmy-ui.service [Unit] Description=Lemmy UI - Web frontend for Lemmy After=lemmy.service Before=nginx.service [Service] User=lemmy WorkingDirectory=/var/lib/lemmy-ui ExecStart=/usr/bin/node dist/js/server.js Environment=LEMMY_INTERNAL_HOST=localhost:8536 Environment=LEMMY_EXTERNAL_HOST=example.com Environment=LEMMY_HTTPS=true Restart=on-failure # Hardening ProtectSystem=full PrivateTmp=true NoNewPrivileges=true [Install] WantedBy=multi-user.targetRun
systemctl enable lemmy-uiandsystemctl start lemmy-uito enable and start the service. -
Verify the Lemmy UI installation by running
curl -I localhost:1234and checking for a200 OKresponse.
Configure Reverse Proxy and TLS
-
Install Nginx and Certbot:
apt install nginx certbot python3-certbot-nginx -
Request a Let’s Encrypt TLS certificate:
certbot certonly --nginxFollow the instructions provided by Certbot to complete the process.
-
Set up automatic certificate renewal by adding a crontab entry:
sudo crontab -eAdd the following line, replacing
example.comwith your actual domain:@daily certbot certonly --nginx --cert-name example.com -d example.com --deploy-hook 'nginx -s reload' -
Download the Nginx configuration file for Lemmy:
curl https://raw.githubusercontent.com/LemmyNet/lemmy-ansible/main/templates/nginx.conf \ --output /etc/nginx/sites-enabled/lemmy.conf -
Replace the variables in the Nginx configuration file:
sed -i -e 's/{{domain}}/example.com/g' /etc/nginx/sites-enabled/lemmy.conf sed -i -e 's/{{lemmy_port}}/8536/g' /etc/nginx/sites-enabled/lemmy.conf sed -i -e 's/{{lemmy_ui_port}}/1234/g' /etc/nginx/sites-enabled/lemmy.conf -
Reload the Nginx configuration:
nginx -s reload -
Open your Lemmy domain in the browser. It should display a configuration screen. Use this screen to create the first admin user and the default community.