Install mihomo on Linux: CLI, systemd Service & Desktop Clients
Run mihomo on Linux desktops or headless servers. Set up its binary and config, create a systemd service, and choose a desktop client.
Binary and Configuration Directories
mihomo is a proxy core descended from Clash Meta. It reads YAML, listens on local ports, and selects an outbound for each connection based on rules. Once the core is running, apps still need to send requests through a local proxy port, or you can configure TUN to route traffic. This guide starts with an explicit proxy setup to help distinguish issues with the app, core, and network.
The commands below use Debian or Ubuntu with systemd. First check the machine architecture and PID 1, then extract the matching Linux release package. x86_64 usually maps to amd64 in release filenames, while aarch64 maps to arm64. If PID 1 is not systemd, as in some containers, you can use the foreground method below, but do not follow the startup-on-boot steps.
uname -m
ps -p 1 -o comm=
sudo install -m 0755 ./mihomo /usr/local/bin/mihomo
/usr/local/bin/mihomo -v
Here, ./mihomo refers to the executable extracted into the current directory and named mihomo. The -v flag prints the installed version; record this output when troubleshooting rather than noting only the desktop client's version. If you get Exec format error, first check that you chose the right architecture and did not try to install the archive itself as a binary.
| Path | Purpose | Permissions |
|---|---|---|
/usr/local/bin/mihomo | Core executable | Installed by an administrator; executable by the service account |
/etc/mihomo/config.yaml | Main configuration | Written by an administrator; read-only for the mihomo group |
/var/lib/mihomo | Core data and writable cache directory | Managed by the service account |
Keep the config and runtime data separate. That way, you can update the YAML without moving the cache or making all of /etc/mihomo writable just to download Providers. If the main config references Providers, rule files, or other local files, check their paths and permissions during migration. Files the core needs to update must be in a directory writable by the service account. If the config contains subscription tokens or proxy credentials, do not paste the full file into public logs or support tickets.
Run in the Foreground: Test Port 7890 First
Create config.yaml in the current directory with this minimal config. mixed-port accepts both HTTP and SOCKS proxy requests on the same port. bind-address and allow-lan restrict this example to local use. MATCH,DIRECT sends all traffic that reaches the final rule directly, so this test does not require a subscription or remote proxy node.
mixed-port: 7890
allow-lan: false
bind-address: "127.0.0.1"
mode: rule
log-level: info
rules:
- MATCH,DIRECT
Run these commands from the directory containing the config. -f explicitly sets the main config file, and -d sets the core data directory. Run -t to check the config first, then remove -t to start the core. A successful config check does not guarantee the port can be bound or that the selected outbound can connect.
mkdir -p "$HOME/.local/state/mihomo-test"
/usr/local/bin/mihomo -t -d "$HOME/.local/state/mihomo-test" -f "$PWD/config.yaml"
/usr/local/bin/mihomo -d "$HOME/.local/state/mihomo-test" -f "$PWD/config.yaml"
Keep this terminal open to watch the logs, then open another terminal to check the listener and make a request. --noproxy '' prevents an existing NO_PROXY environment variable from bypassing this proxy test. --connect-timeout 5 and --max-time 15 limit the connection time and total request time, respectively.
ss -ltnp 'sport = :7890'
curl --noproxy '' --proxy http://127.0.0.1:7890 \
--connect-timeout 5 --max-time 15 -I https://example.com
ss should show a listener on 127.0.0.1:7890. For an HTTPS destination, curl may first print 200 Connection established; this means the local proxy accepted the CONNECT request. Check the destination's response and the core logs to confirm the request actually reached the site. If you see only the local listener and no site response, check the server's DNS and outbound network.
systemd Service: Dedicated Account and Startup on Boot
Install the Config and Test It as the Service User
Create a dedicated system account for the initial installation. Do not use this account for interactive login. If an account named mihomo already exists, confirm it was created for this service before skipping the account-creation command. This example installs config.yaml from the current directory as the live config. Preserve its group and permissions when replacing it later.
sudo useradd --system --user-group --no-create-home \
--home-dir /var/lib/mihomo --shell /usr/sbin/nologin mihomo
sudo install -d -o root -g mihomo -m 0750 /etc/mihomo
sudo install -o root -g mihomo -m 0640 ./config.yaml /etc/mihomo/config.yaml
sudo install -d -o mihomo -g mihomo -m 0750 /var/lib/mihomo
sudo -u mihomo /usr/local/bin/mihomo -t \
-d /var/lib/mihomo -f /etc/mihomo/config.yaml
Test as the service account, not root, to catch files that an administrator can read but the service cannot. If the logs report a missing rule file, check whether it still points to an old location in someone's home directory. This explicit-proxy test uses an unprivileged port, so the core does not need additional network-management permissions.
Create the Service Unit
Run sudoedit /etc/systemd/system/mihomo.service and add the complete unit below. StateDirectory tells systemd to manage /var/lib/mihomo for the service. The core runs as a foreground process that systemd tracks directly; do not append & to ExecStart.
[Unit]
Description=mihomo proxy core
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=mihomo
Group=mihomo
StateDirectory=mihomo
StateDirectoryMode=0750
ExecStart=/usr/local/bin/mihomo -d /var/lib/mihomo -f /etc/mihomo/config.yaml
Restart=on-failure
RestartSec=3s
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
network-online.target sets startup ordering; it does not guarantee that remote subscription URLs are reachable. If the core needs to update remote rules at startup but the network is not ready, check the download errors and local cache instead of relying on the unit status alone. Restart=on-failure attempts to restart the process after an abnormal exit, but it will not fix a bad config.
sudo systemctl daemon-reload
sudo systemctl enable --now mihomo.service
systemctl is-enabled mihomo.service
systemctl status mihomo.service --no-pager
sudo journalctl -u mihomo.service -b -n 80 --no-pager
enabled means the service is configured to start at boot; active (running) means the process is running now. These indicate different states. After enabling the service, repeat the port and curl tests. If you only change the YAML, run -t as the service user first, then run sudo systemctl restart mihomo.service if it passes. Run daemon-reload only after changing the .service file.
Service Fails to Start or Runs Without Traffic
Start with the service logs from the current boot, then troubleshoot based on where the error occurs. System service logs and desktop client logs are separate. If both are installed, first check which listener port the request is actually reaching.
| Symptom | Check first | What to do |
|---|---|---|
Unit shows 203/EXEC | The file specified by ExecStart, its executable permission, and the binary architecture | Run -v using the same absolute path as the unit to confirm that the file at that path can run |
permission denied when reading the config | Read permission on the config file and execute permission on its parent directories | Rerun the config check with sudo -u mihomo and fix the relevant permissions instead of running the entire service as root |
Log reports address already in use | An old foreground process, desktop core, or another listener | Run sudo ss -ltnp 'sport = :7890' to find the process using the port. Stop the duplicate process, or change the port and update the app's proxy address |
| curl works, but the browser bypasses the proxy | Browser or desktop proxy settings, including bypass lists | Set the HTTP proxy actually used by the browser to 127.0.0.1 and 7890, then check the core logs for the request |
| Minimal config works, but requests fail with the full config | The rule that matched, the node selected by the policy group, and Provider loading results | Make sure the request did not unexpectedly fall through to the final MATCH rule, then check node connectivity and destination DNS separately |
If repeated startup failures lead to start request repeated too quickly, systemd has usually hit its start-rate limit after earlier failures. Scroll up to find the first core error, fix it, then run sudo systemctl reset-failed mihomo.service followed by sudo systemctl start mihomo.service. Clearing the failed state does not change the config.
Choosing a Linux Desktop Client or Standalone Core
- Headless servers: Manage mihomo with a system-level systemd service. It does not depend on a desktop session and works well for providing a proxy to local scripts, command-line tools, or specific apps. How each program uses a proxy depends on the program; curl's
--proxyoption does not affect other processes. - Single-user Linux desktops: If you want to switch nodes from the system tray, update subscriptions, or inspect connections, consider a GUI client that can manage the mihomo core. Before choosing a package, check your distribution, architecture, and the actual core it includes. Support for importing Clash YAML does not mean the bundled core supports every mihomo field.
- When you need both a desktop and a system service: Decide which one will start the core. If the GUI client bundles its own core and you no longer need the existing service, run
sudo systemctl disable --now mihomo.servicebefore launching the client. If you keep the system service, first confirm the GUI can connect to an external core. Do not let both programs compete for the same port.
System Proxy and TUN Are Different Ways to Route Traffic
The system proxy only affects apps that read the desktop proxy settings. Some command-line programs need a proxy argument or a setting in their own config. TUN routes traffic through a virtual network interface and involves device access, route management, and DNS configuration. The unprivileged service above does not have the permissions needed for TUN, so setting tun.enable to true in the YAML alone does not complete the setup.
With a desktop session, you can first reproduce the explicit-proxy test using the client's system proxy feature, then decide whether you need TUN. On a server managed over SSH, treat TUN as a separate network change: keep a working management path and a rollback plan, then verify routing and DNS. For proxying only specific programs, a local mixed-port is usually easier to troubleshoot. See the TUN configuration reference for related fields.