]> Untitled Git - lemmy.git/blob - docs/src/contributing_local_development.md
Merge branch 'main' into api_edit_separation
[lemmy.git] / docs / src / contributing_local_development.md
1 ### Install build requirements
2 #### Ubuntu
3 ```
4 sudo apt install git cargo libssl-dev pkg-config libpq-dev yarn curl gnupg2
5 # install yarn
6 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
7 echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
8 sudo apt update && sudo apt install yarn
9 ```
10
11 #### macOS
12
13 Install Rust using [the recommended option on rust-lang.org](https://www.rust-lang.org/tools/install) (rustup).
14
15 Then, install [Homebrew](https://brew.sh/) if you don't already have it installed.
16
17 Finally, install Node and Yarn.
18
19 ```
20 brew install node yarn
21 ```
22
23 ### Get the source code
24 ```
25 git clone https://github.com/LemmyNet/lemmy.git
26 # or alternatively from gitea
27 # git clone https://yerbamate.dev/LemmyNet/lemmy.git
28 ```
29
30 All the following commands need to be run either in `lemmy/server` or `lemmy/ui`, as indicated
31 by the `cd` command.
32
33 ### Build the backend (Rust)
34 ```
35 cd server
36 cargo build
37 # for development, use `cargo check` instead)
38 ```
39
40 ### Build the frontend (Typescript)
41 ```
42 cd ui
43 yarn
44 yarn build
45 ```
46
47 ### Setup postgresql
48 #### Ubuntu
49 ```
50 sudo apt install postgresql
51 sudo systemctl start postgresql
52
53 # Either execute server/db-init.sh, or manually initialize the postgres database:
54 sudo -u postgres psql -c "create user lemmy with password 'password' superuser;" -U postgres
55 sudo -u postgres psql -c 'create database lemmy with owner lemmy;' -U postgres
56 export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
57 ```
58
59 #### macOS
60 ```
61 brew install postgresql
62 brew services start postgresql
63 /usr/local/opt/postgres/bin/createuser -s postgres
64
65 # Either execute server/db-init.sh, or manually initialize the postgres database:
66 psql -c "create user lemmy with password 'password' superuser;" -U postgres
67 psql -c 'create database lemmy with owner lemmy;' -U postgres
68 export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
69 ```
70
71 ### Run a local development instance
72 ```
73 # run each of these in a seperate terminal
74 cd server && cargo run
75 cd ui && yarn start
76 ```
77
78 Then open [localhost:4444](http://localhost:4444) in your browser. It will auto-refresh if you edit
79 any frontend files. For backend coding, you will have to rerun `cargo run`. You can use
80 `cargo check` as a faster way to find compilation errors.
81
82 To speed up incremental builds, you can add the following to `~/.cargo/config`:
83 ```
84 [target.x86_64-unknown-linux-gnu]
85 rustflags = ["-Clink-arg=-fuse-ld=lld"]
86 ```
87
88 Note that this setup doesn't include image uploads or link previews (provided by pict-rs and
89 iframely respectively). If you want to test those, you should use the
90 [Docker development](contributing_docker_development.md).