How to Install Lemmy on Debian Latest
Lemmy is an open-source, federated, and censorship-resistant Reddit clone written in Rust language. In this tutorial, we will be installing Lemmy on Debian Latest.
Prerequisites
Before we start, make sure the following requirements are met:
- A server running Debian Latest
- A user account with sudo privileges
- A domain name pointing to your server IP (optional)
Step 1: Update System Packages
First, we need to update the system packages to the latest version. You can achieve this by running the following command with sudo privileges:
sudo apt update && sudo apt upgrade -y
Step 2: Install Dependencies
Lemmy requires several dependencies to be installed on the system. We can install them by running the following command:
sudo apt install -y pkg-config build-essential git clang libssl-dev libpq-dev postgresql postgresql-contrib redis
This command installs the following packages on your system:
pkg-config: A system for managing library compile and link flags.build-essential: A package that contains the necessary tools for building packages.git: A version control system used to clone the Lemmy source code.clang: A compiler used for compiling Rust libraries.libssl-dev: A development package required by Rust to compile libraries using SSL certificates.libpq-dev: A development package required by Rust to interact with PostgreSQL databases.postgresqlandpostgresql-contrib: Open-source relational database management system.redis: An in-memory data structure store used as a database, cache, and message broker.
Step 3: Install Rust and Cargo
Lemmy is written in Rust language. We need to install Rust and Cargo on our system. This can be done with the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command will install Rustup, a toolchain manager for Rust, and Cargo, a package manager for Rust. After installation, run the following command to add Rust to the PATH:
source $HOME/.cargo/env
Step 4: Clone the Lemmy Repository
Now, we need to clone the Lemmy repository from GitHub. You can do this with the following command:
git clone https://github.com/LemmyNet/lemmy.git
This command will clone the latest master branch of Lemmy to your system.
Step 5: Configure and Build Lemmy
Before we can build and configure Lemmy, we need to create a PostgreSQL database and a user for Lemmy. Run the following commands to create a database and a user:
sudo su - postgres
psql
CREATE DATABASE lemmy;
CREATE USER lemmy WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE lemmy TO lemmy;
\q
exit
To configure Lemmy, you need to create a .env file in the root directory of the cloned repository. We can copy the .env.example file to the .env file with the following command:
cd lemmy
cp .env.example .env
Open the .env file with your favourite text editor and add the following configuration:
DATABASE_URL=postgresql://lemmy:[email protected]:5432/lemmy
DOMAIN=lemmy.example.com
ROCKET_SECRET_KEY=CHANGE_ME
ROCKET_PORT=8544
REDIS_URL=redis://localhost
DATABASE_URL: The connection URL for the PostgreSQL database we created earlier.DOMAIN: The domain name where you want to access Lemmy.ROCKET_SECRET_KEY: A secret key used by the Rocket web framework.ROCKET_PORT: The port number on which Lemmy will listen to.REDIS_URL: The connection URL for Redis.
Next, we need to build Lemmy with the following command:
cargo build --bin lemmy_server --release
This command will build the Lemmy server in the release mode. The executable will be located at target/release/lemmy_server.
Step 6: Configure and Run Lemmy
To run Lemmy, you need to configure the web server or reverse proxy. We will configure Nginx as a reverse proxy in this tutorial.
Install Nginx with the following command:
sudo apt install -y nginx
Create a new configuration file for Lemmy with the following command:
sudo nano /etc/nginx/sites-available/lemmy.conf
Add the following configuration to the file:
server {
listen 80;
server_name lemmy.example.com;
location / {
proxy_pass http://localhost:8544;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Replace lemmy.example.com with your domain name. Save and close the file.
Enable the Lemmy configuration by creating a symbolic link:
sudo ln -s /etc/nginx/sites-available/lemmy.conf /etc/nginx/sites-enabled
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Finally, start Lemmy with the following command:
ROCKET_ENV=production ./target/release/lemmy_server
You can now access Lemmy by visiting http://lemmy.example.com.
Conclusion
In this tutorial, we showed you how to install and configure Lemmy on Debian Latest. We hope that this tutorial has helped you get started with this great alternative to Reddit.