Install Dify

Dify is an open-source platform for building AI applications. It combines Backend-as-a-Service and LLMOps to streamline the development of generative AI solutions, making it accessible to both developers and non-technical innovators.

The platform integrates:

  • Support for mainstream LLMs
  • An intuitive Prompt orchestration interface
  • High-quality RAG engines
  • A flexible AI Agent framework
  • An Intuitive Low-code Workflow
  • Easy-to-use interfaces and APIs

With Dify, you can skip the complexity and focus on what matters most – creating innovative AI applications that solve real-world problems.

While many AI development tools offer individual components, Dify provides a comprehensive, production-ready solution.

With Dify, you can:

  • Deploy capabilities similar to Assistants API and GPTs using any model
  • Maintain full control over your data with flexible security options
  • Leverage an intuitive interface for easy management and deployment

Before installing Dify, make sure your machine meets the following minimum system requirements:

  • CPU >= 2 Core
  • RAM >= 4GB

Linux on Windows with WSL

You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to use the commands below.

WSL command

You can now install everything you need to run WSL with a single command. Open PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting “Run as administrator”, enter the wsl –install command, then restart your machine.

wsl --install

This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux. (This default distribution can be changed).

The first time you launch a newly installed Linux distribution, a console window will open and you’ll be asked to wait for files to de-compress and be stored on your machine. All future launches should take less than a second.

 Note:

The above command only works if WSL is not installed at all. If you run wsl --install and see the WSL help text, please try running wsl --list --online to see a list of available distros and run wsl --install -d <DistroName> to install a distro. 

Change the default Linux distribution installed

By default, the installed Linux distribution will be Ubuntu. This can be changed using the -d flag.

  • To change the distribution installed, enter: wsl --install -d <Distribution Name>. Replace <Distribution Name> with the name of the distribution you would like to install.
  • To see a list of available Linux distributions available for download through the online store, enter: wsl --list --online or wsl -l -o.
  • To install additional Linux distributions after the initial install, you may also use the command: wsl --install -d <Distribution Name>.
Set up your Linux username and password

Once the process of installing your Linux distribution with WSL is complete, open the distribution (Ubuntu by default) using the Start menu. You will be asked to create a User Name and Password for your Linux distribution.

  • This User Name and Password is specific to each separate Linux distribution that you install and has no bearing on your Windows user name.
  • Please note that whilst entering the Password, nothing will appear on screen. This is called blind typing. You won’t see what you are typing, this is completely normal.
  • Once you create a User Name and Password, the account will be your default user for the distribution and automatically sign-in on launch.
  • This account will be considered the Linux administrator, with the ability to run sudo (Super User Do) administrative commands.
  • Each Linux distribution running on WSL has its own Linux user accounts and passwords. You will have to configure a Linux user account every time you add a distribution, reinstall, or reset.

Note:

Linux distributions installed with WSL are a per-user installation and can’t be shared with other Windows user accounts. Encountering a username error? StackExchange: What characters should I use or not use in usernames on Linux?

To change or reset your password, open the Linux distribution and enter the command: passwd. You will be asked to enter your current password, then asked to enter your new password, and then to confirm your new password.

If you forgot the password for your Linux distribution:

  1. Open PowerShell and enter the root of your default WSL distribution using the command: wsl -u rootIf you need to update the forgotten password on a distribution that is not your default, use the command: wsl -d Debian -u root, replacing Debian with the name of your targeted distribution.
  2. Once your WSL distribution has been opened at the root level inside PowerShell, you can use this command to update your password: passwd <username> where <username> is the username of the account in the distribution whose password you’ve forgotten.
  3. You will be prompted to enter a new UNIX password and then confirm that password. Once you’re told that the password has updated successfully, close WSL inside of PowerShell using the command: exit.
Update and upgrade packages

We recommend that you regularly update and upgrade your packages using the preferred package manager for the distribution. For Ubuntu or Debian, use the command:

sudo apt update && sudo apt upgrade

Windows does not automatically update or upgrade your Linux distribution(s). This is a task that most Linux users prefer to control themselves.

Docker Desktop on Windows

  1. Download the installer using the download button at the top of the page, or from the release notes.
  2. Double-click Docker Desktop Installer.exe to run the installer. By default, Docker Desktop is installed at C:\Program Files\Docker\Docker.
  3. When prompted, ensure the Use WSL 2 instead of Hyper-V option on the Configuration page is selected or not depending on your choice of backend.If your system only supports one of the two options, you won’t be able to select which backend to use.
  4. Follow the instructions on the installation wizard to authorize the installer and proceed with the install.
  5. When the installation is successful, select Close to complete the installation process.
  6. Start Docker Desktop.

Start Docker Desktop

Docker Desktop does not start automatically after installation. To start Docker Desktop:

  1. Search for Docker, and select Docker Desktop in the search results.
  2. The Docker menu ( whale menu ) displays the Docker Subscription Service Agreement.Here’s a summary of the key points:
    • Docker Desktop is free for small businesses (fewer than 250 employees AND less than $10 million in annual revenue), personal use, education, and non-commercial open source projects.
    • Otherwise, it requires a paid subscription for professional use.
    • Paid subscriptions are also required for government entities.
    • The Docker Pro, Team, and Business subscriptions include commercial use of Docker Desktop.
  3. Select Accept to continue. Docker Desktop starts after you accept the terms.Note that Docker Desktop won’t run if you do not agree to the terms. You can choose to accept the terms at a later date by opening Docker Desktop.

Configure Dify

Clone Dify

Clone the Dify source code to your local machine:

git clone https://github.com/langgenius/dify.git
Starting Dify
  1. Navigate to the Docker directory in the Dify source code
cd dify/docker
  1. Copy the environment configuration file
cp .env.example .env
  1. Start the Docker containers

Choose the appropriate command to start the containers based on the Docker Compose version on your system. You can use the $ docker compose version command to check the version, and refer to the Docker documentation for more information:

docker compose up -d

docker-compose up -d

After executing the command, you should see output similar to the following, showing the status and port mappings of all containers:

[+] Running 11/11
 ✔ Network docker_default             Created                    0.0s       
 ✔ Network docker_ssrf_proxy_network  Created                    0.0s
 ✔ Container docker-weaviate-1        Started                    2.0s
 ✔ Container docker-db-1              Started                    2.1s
 ✔ Container docker-ssrf_proxy-1      Started                    2.2s
 ✔ Container docker-redis-1           Started                    2.2s
 ✔ Container docker-web-1             Started                    2.0s
 ✔ Container docker-sandbox-1         Started                    2.2s
 ✔ Container docker-api-1             Started                    2.5s
 ✔ Container docker-worker-1          Started                    2.7s
 ✔ Container docker-nginx-1           Started                    2.8s

Finally, check if all containers are running successfully:

docker compose ps

This includes 3 core services: api / worker / web, and 6 dependent components: weaviate / db / redis / nginx / ssrf_proxy / sandbox .

NAME                  IMAGE                              COMMAND                  SERVICE      CREATED         STATUS                   PORTS
docker-api-1          langgenius/dify-api:0.7.0          "/bin/bash /entrypoi…"   api          8 minutes ago   Up 8 minutes             5001/tcp
docker-db-1           postgres:15-alpine                 "docker-entrypoint.s…"   db           8 minutes ago   Up 8 minutes (healthy)   5432/tcp
docker-nginx-1        nginx:latest                       "sh -c 'cp /docker-e…"   nginx        8 minutes ago   Up 8 minutes             0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp
docker-redis-1        redis:6-alpine                     "docker-entrypoint.s…"   redis        8 minutes ago   Up 8 minutes (healthy)   6379/tcp
docker-sandbox-1      langgenius/dify-sandbox:0.2.1      "/main"                  sandbox      8 minutes ago   Up 8 minutes
docker-ssrf_proxy-1   ubuntu/squid:latest                "sh -c 'cp /docker-e…"   ssrf_proxy   8 minutes ago   Up 8 minutes             3128/tcp
docker-weaviate-1     semitechnologies/weaviate:1.19.0   "/bin/weaviate --hos…"   weaviate     8 minutes ago   Up 8 minutes
docker-web-1          langgenius/dify-web:0.7.0          "/bin/sh ./entrypoin…"   web          8 minutes ago   Up 8 minutes             3000/tcp
docker-worker-1       langgenius/dify-api:0.7.0          "/bin/bash /entrypoi…"   worker       8 minutes ago   Up 8 minutes             5001/tcp

With these steps, you should be able to install Dify successfully.

Upgrade Dify

Enter the docker directory of the dify source code and execute the following commands:

cd dify/docker
docker compose down
git pull origin main
docker compose pull
docker compose up -d

Sync Environment Variable Configuration (Important)

  • If the .env.example file has been updated, be sure to modify your local .env file accordingly.
  • Check and modify the configuration items in the .env file as needed to ensure they match your actual environment. You may need to add any new variables from .env.example to your .env file, and update any values that have changed.
Access Dify

Access administrator initialization page to set up the admin account:

# Local environment
http://localhost/install

# Server environment
http://your_server_ip/install

Dify web interface address:

# Local environment
http://localhost

# Server environment
http://your_server_ip
Customize Dify

Edit the environment variable values in your .env file directly. Then, restart Dify with:

docker compose down
docker compose up -d

The full set of annotated environment variables along can be found under docker/.env.example.