[Updated] Install Lemmy - Self-Hosted Reddit Alternative - on Linux
#Lemmy #Self-Hosted #Linux
Full steps can be found at https://i12bretro.github.io/tutorials/0675.html
What is Lemmy?
Lemmy is an open-source, federated link aggregator similar to Reddit and built with Rust. - https://lemmy.ml/
01. Log into the Linux device
02. Run the following commands in a terminal window
# update software repositories
sudo apt update
# install available software updates
sudo apt upgrade -y
# install prerequisites
sudo apt install git build-essential gcc libssl-dev pkg-config libpq-dev curl gnupg2 espeak postgresql -y
# enable the postgresql service and start it
sudo systemctl enable postgresql --now
# connect to postgresql
sudo -u postgres psql postgres
# create lemmy database user
create user lemmy with password 'L3mmy' superuser;
# create lemmy database
create database lemmy with owner lemmy;
# close postgresql connection
exit
# add nodejs software repository
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
# install nodejs
sudo apt install nodejs -y
# install yarn
sudo npm install -g yarn
# create lemmy user
sudo useradd -m -d /opt/lemmy lemmy
# install rust, enter 1 at the prompt
curl https://sh.rustup.rs -sSf | sh
# configure the shell
source "$HOME/.cargo/env"
# lookup the latest tagged release
regex='\/([0-9|\.]*)≪\/id≫' && response=$(curl -s https://github.com/LemmyNet/lemmy/releases.atom) && [[ $response =~ $regex ]] && latestTag="${BASH_REMATCH[1]}"
# clone the lemmy git repository
git clone https://github.com/LemmyNet/lemmy.git ./server
# change directory to the source code
cd server
# checkout the latest tag
git checkout $latestTag
# update submodules
git submodule update --init --recursive
# generate a random 32 character string
openssl rand -base64 32
# edit the lemmy config file
nano ./config/config.hjson
03. Set the following values in the conf file
database: {
password: L3mmy
}
hostname: ≪% DNS or IP of host %≫
bind: "127.0.0.1"
tls_enabled: false
jwt_secret: "≪% Random string from above %≫"
04. Press CTRL+O, Enter, CTRL+X to write the changes
05. Continue with the following commands
# set the database connection variable
LEMMY_DATABASE_URL=postgres://lemmy:L3mmy@localhost:5432/lemmy
# build lemmy
cargo build --release
# change directory out of lemmy server
cd ..
# write the version to .txt
echo $latestTag ≫ /tmp/lemmy_version.txt
# move lemmy to /opt/lemmy
sudo mv ./server /opt/lemmy/
# switch user to lemmy
sudo su lemmy
# change directory to lemmy home
cd ~
# print working directory, should output /opt/lemmy
pwd
# clone lemmy frontend
git clone https://github.com/LemmyNet/lemmy-ui.git --recurse-submodules ./lemmy-ui
# change directory to lemmy-ui
cd lemmy-ui
# checkout the latest tag
git checkout $(cat /tmp/lemmy_version.txt)
# update submodules
git submodule update --init --recursive
# install npm dependencies
npm install --force
# build lemmy-ui
yarn build:prod
# exit lemmy shell
exit
# set owner of /opt/lemmy
sudo chown lemmy:lemmy /opt/lemmy/ -R
# create lemmy service file
sudo nano /etc/systemd/system/lemmy.service
06. Paste the following configuration into lemmy.service
[Unit]
Description=Lemmy
[Service]
User=lemmy
Group=lemmy
Environment=LEMMY_DATABASE_URL=postgres://lemmy:L3mmy@localhost:5432/lemmy
ExecStart=/opt/lemmy/server/target/release/lemmy_server
WorkingDirectory=/opt/lemmy/server
[Install]
WantedBy=multi-user.target
07. Press CTRL+O, Enter, CTRL+X to write the changes
08. Continue with the following commands
# create lemmy-ui service bash file
sudo nano /opt/lemmy/lemmy-ui/lemmy-ui.sh
09. Paste the following configuration into lemmy-ui.sh
#!/usr/bin/bash
/usr/bin/node /opt/lemmy/lemmy-ui/dist/js/server.js
10. Continue with the following commands
# make lemmy-ui.sh executable
sudo chmod +x /opt/lemmy/lemmy-ui/lemmy-ui.sh
# create lemmy service file
....Full steps can be found on GitHub [link at the top]
### Connect with me and others ###
★ Discord: https://discord.com/invite/EzenvmSHW8
★ Reddit: https://reddit.com/r/i12bretro
★ Twitter: https://twitter.com/i12bretro