Automating AI Agents with n8n
n8n Installation
Get n8n Running
The best way to run a self-hosted version of n8n is with Docker. Docker packages applications into isolated environments called containers. This keeps n8n and its dependencies separate from the rest of your system, making installation clean and simple.
Before you can install n8n, you need to have Docker installed on your machine. If you don't already have it, you can download Docker Desktop for Mac and Windows, or Docker Engine for Linux, from the official Docker website. Once Docker is up and running, you're ready to proceed.
Pull the n8n Image
The first step is to download the official n8n Docker image. An image is a blueprint that contains everything needed to run an application. You'll pull this image from Docker Hub, a public registry for container images. Open your terminal or command prompt and run the following command:
docker pull n8nio/n8n
This command fetches the latest version of the n8n image and saves it to your local machine. You only need to do this once, or whenever you want to update to a newer version.
Run the n8n Container
With the image downloaded, you can now start n8n as a container. The docker run command creates and starts a new container from the image you just pulled. Here's a basic command to get started:
docker run -it --rm --name n8n -p 5678:5678 n8nio/n8n
Let's break down what each part of that command does:
| Flag | Purpose |
|---|---|
-it | Attaches your terminal to the container, allowing you to see logs and interact with it. |
--rm | Automatically removes the container when it's stopped. This is great for a clean slate every time. |
--name n8n | Assigns a memorable name to your container, making it easier to manage. |
-p 5678:5678 | Maps port 5678 on your machine to port 5678 inside the container. This lets you access the n8n UI in your browser. |
n8nio/n8n | Specifies the image to use for creating the container. |
After running this command, n8n will start up. You can then open a web browser and navigate to http://localhost:5678 to access the n8n editor and start building workflows.
The
--rmflag is useful for testing, but it means any workflows you create will be lost when you stop the container. For persistent data, you'll need to mount a volume.
Saving Your Work
To save your workflows and credentials, you need to give the container a dedicated place to store its data on your computer. This is done using a Docker volume. A volume links a directory on your machine to a directory inside the container.
First, create a directory on your computer where you want to store the n8n data. A common choice is to create a .n8n folder in your home directory. Then, modify the docker run command to include the -v (volume) flag:
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
The new line, -v ~/.n8n:/home/node/.n8n, tells Docker to map the ~/.n8n directory on your host machine to the /home/node/.n8n directory inside the container, which is where n8n stores all its data. Now, your workflows will be saved even after you stop and restart the container.
Basic Configuration
You can configure your n8n instance by passing in environment variables with the -e flag. These variables allow you to customize settings without modifying any files.
For example, you might want to set the time zone for your n8n instance so that time-based triggers work as expected. You can do this by adding an environment variable for GENERIC_TIMEZONE.
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
-e GENERIC_TIMEZONE="Europe/Berlin" \
n8nio/n8n
This command does everything the previous one did, but it also sets the instance's time zone to Berlin. You can find a full list of configuration variables in the official n8n documentation.
What is the primary benefit of using Docker to run a self-hosted n8n instance?
Which command correctly downloads the latest official n8n image from Docker Hub to your local machine?
You now have a fully functional, self-hosted n8n instance running on your machine. You're ready to start automating.