If you want to help with the development or just want to test things with your own Lemmy instance, you will have to set up a local instance on your own PC. This is not that hard, but it is not uncommon that you will do something wrong and if you are not, that experienced with the technology that is used, it can be hard to understand the error messages that you receive. That’s why I wrote this blog to help developers to run their own local instance.
So when setting up your local instance, it is a good idea to read the official guide for local development. We will now set up both the API/back-end and the front-end.
The back-end
First, we need the rust toolchain. The easiest way is to just get Rustup by following the installation command you find on this website.
Now before we start checking or building the back-end we need to install all required libraries.
For Debian-based (like Ubuntu) this is:
sudo apt install git cargo libssl-dev pkg-config libpq-dev curl postgresql
For Arch-based this is:
sudo pacman -S git cargo libssl-dev pkg-config libpq-dev curl postgresql
For macOS, you can just install postgresql:
brew install postgresql brew services start postgresql /usr/local/opt/postgres/bin/createuser -s postgres
Now we need to add a db user for Lemmy to the database.
Sometimes psql cannot be found, in those cases you can often just switch to the postgresql user with sudo su postgres
psql -c "create user lemmy with password 'password' superuser;" -U postgres psql -c 'create database lemmy with owner lemmy;' -U postgres
You can change the password if you want, in that case remember the password you entered.
Now we have everything we need for the back-end, it is time to download the Lemmy project.
git clone https://github.com/LemmyNet/lemmy.git --recursive git clone https://github.com/LemmyNet/lemmy-ui.git --recursive
Make sure you don’t forget the --recursive flag, it is required to download all the code.
Now we can have a look at the configuration of the back-end. In the “lemmy” project there should be a folder named “config”, in this config file are 2 files, defaults.hjson and config.hjson. If you need to make settings to your server, you can make those in the config.hjson file. You can use this to change the password of the database, for example. The defaults.hjson file should help with finding out how this can be done.
Now we can check if everything works correctly, open a shell in the “lemmy” project (this is the back-end). There should be a Cargo.toml file in this folder.
Here you can now run cargo check
to check if everything compiles. This should run fine, and then you can run cargo run
. Now you should have a running server.
After making changes, you need to format the code with cargo +nightly fmt --all and run the linter with ./scripts/fix-clippy.sh
.
The front-end
To get started with the front-end we need both Node and Yarn. Node is available through brew with “brew install node”, but you can also install it from the Node.js website. For many Linux distributions, it is also possible to use your package manager.
Then we still need Yarn, there are again multiple ways to install Yarn, the recommended way to install yarn is trough corepack, this is explained on the yarn website. You can also install it through brew with “brew install yarn” or simply trough npm with npm install -g yarn
. I went for the npm route.
After installing yarn, you can install all node dependencies with yarn install
and start the development server with yarn start
.
Image uploads
We did not set up an image server, so you won’t be able to upload images. The docker setup does support this, but for general development building the docker containers is too slow.
Windows
I haven’t tried this out on Windows, but you should be able to follow all the Linux steps with Windows subsystem for Linux. You might be able to get it to work natively, but some installation steps will be different.
deleted by creator