--- title: Configuració local description: "La guia per a col·laboradors (o desenvolupadors curiosos) que volen executar Twenty localment." image: /images/user-guide/fields/field.png --- Header ## Prerequisits Abans d'instal·lar i utilitzar Twenty, assegura't d'instal·lar el següent al teu ordinador: - [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - [Node v24.5.0](https://nodejs.org/en/download) - [yarn v4](https://yarnpkg.com/getting-started/install) - [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) `npm` no funcionarà, has d'utilitzar `yarn` en el seu lloc. Ara Yarn s'entrega amb Node.js, per tant, no cal instal·lar-lo per separat. Només has d'executar `corepack enable` per habilitar Yarn si encara no ho has fet. 1. Instal·la WSL Obre PowerShell com a administrador i executa: ```powershell wsl --install ``` Ara hauríeu de veure un missatge per reiniciar l'ordinador. Si no, reinicia'l manualment. En reiniciar-se, s'obrirà una finestra de PowerShell i instal·larà Ubuntu. Això pot trigar una mica de temps. Veureu un missatge per crear un nom d'usuari i una contrasenya per a la vostra instal·lació d'Ubuntu. 2. Instal·la i configura git ```bash sudo apt-get install git git config --global user.name "Your Name" git config --global user.email "youremail@domain.com" ``` 3. Instal·la nvm, node.js i yarn Utilitzeu `nvm` per instal·lar la versió correcta de `node`. El `.nvmrc` assegura que tots els col·laboradors utilitzin la mateixa versió. ```bash sudo apt-get install curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash ``` Tanca i obre de nou el teu terminal per utilitzar nvm. Després executa les següents comandes. ```bash nvm install # installs recommended node version nvm use # use recommended node version corepack enable ``` --- ## Pas 1: Clonació de Git Al teu terminal, executa la següent comanda. If you haven't already set up SSH keys, you can learn how to do so [here](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh). ```bash git clone git@github.com:twentyhq/twenty.git ``` ```bash git clone https://github.com/twentyhq/twenty.git ``` ## Pas 2: Posa't a l'arrel ```bash cd twenty ``` Hauries d'executar totes les comandes dels passos següents des de l'arrel del projecte. ## Pas 3: Configurar una base de dades PostgreSQL **Option 1 (preferred):** To provision your database locally: Use the following link to install Postgresql on your Linux machine: [Postgresql Installation](https://www.postgresql.org/download/linux/) ```bash psql postgres -c "CREATE DATABASE \"default\";" -c "CREATE DATABASE test;" ``` Note: You might need to add `sudo -u postgres` to the command before `psql` to avoid permission errors. ```` **Option 2:** If you have docker installed: ```bash make postgres-on-docker ``` ```` **Option 1 (preferred):** To provision your database locally with `brew`: ```` ```bash brew install postgresql@16 export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH" brew services start postgresql@16 psql postgres -c "CREATE DATABASE \"default\";" -c "CREATE DATABASE test;" ``` You can verify if the PostgreSQL server is running by executing: ```bash brew services list ``` The installer might not create the `postgres` user by default when installing via Homebrew on MacOS. Instead, it creates a PostgreSQL role that matches your macOS username (e.g., "john"). To check and create the `postgres` user if necessary, follow these steps: ```bash # Connect to PostgreSQL psql postgres or psql -U $(whoami) -d postgres ``` Once at the psql prompt (postgres=#), run: ```bash # List existing PostgreSQL roles \du ``` You'll see output similar to: ```bash Role name | Attributes | Member of -----------+-------------+----------- john | Superuser | {} ``` If you do not see a `postgres` role listed, proceed to the next step. Create the `postgres` role manually: ```bash CREATE ROLE postgres WITH SUPERUSER LOGIN; ``` This creates a superuser role named `postgres` with login access. **Option 2:** If you have docker installed: ```bash make postgres-on-docker ``` ```` All the following steps are to be run in the WSL terminal (within your virtual machine) ```` **Option 1:** To provision your Postgresql locally: Use the following link to install Postgresql on your Linux virtual machine: [Postgresql Installation](https://www.postgresql.org/download/linux/) ```bash psql postgres -c "CREATE DATABASE \"default\";" -c "CREATE DATABASE test;" ``` Note: You might need to add `sudo -u postgres` to the command before `psql` to avoid permission errors. **Option 2:** If you have docker installed: Running Docker on WSL adds an extra layer of complexity. Only use this option if you are comfortable with the extra steps involved, including turning on [Docker Desktop WSL2](https://docs.docker.com/desktop/wsl). ```bash make postgres-on-docker ``` ```` Ara pots accedir a la base de dades a [localhost:5432](localhost:5432), amb l'usuari `postgres` i la contrasenya `postgres`. ## Pas 4: Configura una base de dades Redis (caché) Twenty requereix una caché de Redis per proporcionar el millor rendiment **Option 1:** To provision your Redis locally: Use the following link to install Redis on your Linux machine: [Redis Installation](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/) ```` **Option 2:** If you have docker installed: ```bash make redis-on-docker ``` ```` **Option 1 (preferred):** To provision your Redis locally with `brew`: ```bash brew install redis ``` Start your redis server: ```brew services start redis``` ```` **Option 2:** If you have docker installed: ```bash make redis-on-docker ``` ```` **Option 1:** To provision your Redis locally: Use the following link to install Redis on your Linux virtual machine: [Redis Installation](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/) ```` **Option 2:** If you have docker installed: ```bash make redis-on-docker ``` ```` Si necessites una interfície gràfica de client, recomanem [redis insight](https://redis.io/insight/) (versió gratuïta disponible) ## Pas 5: Configura les variables d'entorn Use environment variables or `.env` files to configure your project. Més informació [aquí](https://docs.twenty.com/l/ca/developers/self-hosting/setup) Copy the `.env.example` files in `/front` and `/server`: ```bash cp ./packages/twenty-front/.env.example ./packages/twenty-front/.env cp ./packages/twenty-server/.env.example ./packages/twenty-server/.env ``` ## Pas 6: Instal·lació de dependències Per construir el servidor Twenty i afegir algunes dades a la base de dades, executa la següent comanda: ```bash yarn ``` Nota que `npm` o `pnpm` no funcionaran ## Pas 7: Executar el projecte Depenent de la teva distribució Linux, el servidor de Redis podria iniciar-se automàticament. Si no, consulteu la [guia d'instal·lació de Redis](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/) per a la vostra distro. Redis ja hauria d'estar funcionant. If not, run: ```bash brew services start redis ``` Depenent de la teva distribució Linux, el servidor de Redis podria iniciar-se automàticament. Si no, consulteu la [guia d'instal·lació de Redis](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/) per a la vostra distro. Set up your database with the following command: ```bash npx nx database:reset twenty-server ``` Inicia el servidor, el treballador i els serveis de frontend: ```bash npx nx start twenty-server npx nx worker twenty-server npx nx start twenty-front ``` Alternativament, pots iniciar tots els serveis alhora: ```bash npx nx start ``` ## Pas 8: Utilitzar Twenty **Frontend** El frontend de Twenty estarà funcionant a [http://localhost:3001](http://localhost:3001). Podeu iniciar sessió utilitzant el compte de demostració per defecte: `tim@apple.dev` (contrasenya: `tim@apple.dev`) **Backend** - El servidor de Twenty estarà en funcionament a [http://localhost:3000](http://localhost:3000) - L'API GraphQL es pot accedir a [http://localhost:3000/graphql](http://localhost:3000/graphql) - Es pot accedir a l'API REST a [http://localhost:3000/rest](http://localhost:3000/rest) ## Resolució de problemes Si trobeu algun problema, consulteu [Resolució de problemes](https://docs.twenty.com/l/ca/developers/self-hosting/troubleshooting) per trobar solucions.