Local Development

Install build requirements

Install the latest Rust version using rustup.

Debian-based distro:

sudo apt install git cargo libssl-dev pkg-config libpq-dev curl

Arch-based distro:

sudo pacman -S git cargo openssl pkg-config postgresql-libs curl

macOS:

Install Homebrew if you don't already have it installed. Then install Node and pnpm.

brew install node

Install pnpm

The install instructions are here, or you can run

npm install -g pnpm

Setup PostgreSQL database

Debian-based distro:

sudo apt install postgresql
sudo systemctl start postgresql

Arch-based distro:

sudo pacman -S postgresql
sudo systemctl start postgresql
# If the systemctl command errors, then run the following
sudo mkdir /var/lib/postgres/data
sudo chown postgres:postgres /var/lib/postgres/data
sudo -u postgres initdb -D /var/lib/postgres/data
sudo systemctl start postgresql

macOS:

brew install postgresql
brew services start postgresql
$(brew --prefix postgresql)/bin/createuser -s postgres

Either execute scripts/db-init.sh, or manually initialize the postgres database:

psql -c "create user lemmy with password 'password' superuser;" -U postgres
psql -c 'create database lemmy with owner lemmy;' -U postgres
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy

Get the code

Clone frontend and backend code to local folders. Be sure to include --recursive to initialize git submodules.

git clone https://github.com/LemmyNet/lemmy.git --recursive
git clone https://github.com/LemmyNet/lemmy-ui.git --recursive

Backend development

Use cargo check to find compilation errors. To start the Lemmy backend, run cargo run. It will bind to 0.0.0.0:8536.

After making changes, you need to format the code with cargo +nightly fmt --all and run the linter with ./scripts/lint.sh.

Frontend development

Install dependencies by running pnpm i. Then run pnpm dev to launch lemmy-ui locally. It automatically connects to the Lemmy backend on localhost:8536. Open localhost:1234 in your browser. The project is rebuilt automatically when you change any files.

Note that this setup doesn't support image uploads. If you want to test those, you need to use the Docker development.

Tests

Run Rust unit tests:

./scripts/test.sh

To run federation/API tests, first add the following lines to /etc/hosts:

127.0.0.1       lemmy-alpha
127.0.0.1       lemmy-beta
127.0.0.1       lemmy-gamma
127.0.0.1       lemmy-delta
127.0.0.1       lemmy-epsilon

Then run the following script:

cd api_tests
./run-federation-test.sh