Complete Uninstallation and Cleanup of Local AI Agent Services
This article provides a comprehensive guide on thoroughly uninstalling and cleaning up local AI agent services. It outlines the proper sequence of stopping daemon processes, removing program files, clearing hidden configurations and logs, checking system startup items, and verifying the results to prevent process leftovers, unexpected service restarts, and credential leaks.
Complete Uninstallation and Cleanup of Local AI Agent Services
1. Scope and Principles of Uninstallation
A local AI agent service typically consists of three components: a resident background daemon, program files installed on the system, and configurations, databases, and logs saved in the user directory. Simply deleting the program files often leaves behind running processes, startup items, and configuration files containing credentials. These residuals pose three types of risks:
- While processes are still running, associated files may be locked, causing deletion to fail or leave incomplete directories.
- Startup items will restart the service on the next login, causing resource consumption or unexpected network connections.
- Configuration files may contain access tokens and API keys. Leaving them uncleaned poses a security risk of credential leaks.
Therefore, the uninstallation should follow a specific sequence: first stop the service and unregister the daemon, then delete the program files, followed by cleaning up user data, and finally checking system-level startup items. Confirm the result after each step before proceeding to the next. It is recommended to back up any data you need to keep before operating, and ensure all paths and commands point to the correct targets.
2. Step 1: Stop and Unregister the Background Daemon
The daemon is responsible for keeping the service running in the background. If you delete the program directly, the process may still hold file handles, leading to incomplete deletion. Therefore, the first step is to stop the process and remove its service registration.
Execute the built-in management commands in the terminal. Replace <service_name> with the actual installed command-line name:
<service_name> gateway stop<service_name> gateway uninstall
The first command stops the running process, and the second command removes the service registration information so the system will no longer attempt to start it.
If earlier versions were installed under a different name, the command-line name may have changed. In this case, try the corresponding commands for the old names. If it prompts that the command is not found, it means the name was never installed, and you can skip it.
After execution, use the system’s process viewing command to confirm that there are no residual processes:
ps aux | grep <keyword>
If related processes are still present in the output, note their process IDs (PIDs) and decide whether to terminate them manually. Before manual termination, confirm that the process actually belongs to the target service to avoid accidentally stopping other programs.
3. Step 2: Delete Program Files
The location of the program files depends on the installation method. There are two common installation methods, each with a different cleanup approach.
| Installation Method | Characteristics | Cleanup Strategy |
|---|---|---|
| Global Package Manager | Commands can be called directly from any directory | Use the corresponding package manager used during installation to perform a global uninstall |
| Source Code Clone | Contains a complete project directory | Confirm the directory path and delete the entire directory |
3.1 Global Package Manager Installation
If installed globally using a JavaScript ecosystem-based package manager, you should uninstall it using the same package manager. Different package managers have different command formats, but the logic is the same:
<package_manager> uninstall -g <package_name>
The package name may include the current name and historical names. Listing all possible package names at once prevents missing older versions. If you are unsure which package manager was used initially, you can execute the corresponding global list commands to view the installed packages and uninstall them accordingly.
3.2 Source Code Clone Installation
If the source code was pulled from a version control system, the program itself is a project directory. Before uninstalling, confirm the directory path. Common locations include subdirectories under the user’s home directory and Documents folder.
ls -la ~ls -la ~/Documents
After confirming the directory, it is recommended to use the interactive deletion command to confirm each item:
rm -ri <target_directory_path>
Before deleting, check whether the directory contains uncommitted changes or custom configurations. If there is anything you need to keep, copy it to another location first.
4. Step 3: Clean Up Hidden Configurations, Data, and Logs
This step is the key to a complete uninstallation. Services usually create hidden directories starting with a dot (.) in the user’s home directory to store API keys, local databases, running states, and logs. These files will not automatically disappear when the program is deleted.
4.1 Find Residual Directories
First, list the hidden directories in the user’s home directory related to the service name to confirm the actual existing paths:
ls -la ~ | grep -E "<keyword1>|<keyword2>"
Keywords should include both the current and historical names. The search results may include the configuration directory, data directory, and workspace cache directory.
4.2 Handle Credentials and Data
Before deleting, determine what needs to be kept.
- Configuration files may store API keys or access tokens. Before deleting, record their purposes and revoke or rotate these credentials on the corresponding platforms to prevent them from remaining valid in residual files.
- Database files may contain historical sessions or business data. If you need to keep them, export or copy them to a separate location first.
- Log files can usually be deleted directly, but if they are still needed for troubleshooting, archive them first.
Once you confirm there is nothing to keep, delete the residual directories one by one:
rm -ri ~/.<directory_name>rm -ri ~/<workspace_cache_directory>
Using interactive deletion allows you to see a confirmation prompt at each step, reducing the risk of accidental deletion. It is not recommended to use forced recursive deletion without confirmation, especially when the path contains wildcards or variables. If a variable is empty, the path might be expanded to a higher-level directory, causing irreversible data loss.
5. Step 4: Check System-Level Startup Items
Even if the daemon has been unregistered, configuration files that automatically start on boot or login may still remain in the system. These files are usually located in the user-level startup item directory, and the exact path varies by operating system.
Look for related files in the corresponding directory:
ls <user_startup_item_directory> | grep -E "<keyword>"
If configuration files are found, you should first uninstall the service through the system’s service management tool before deleting the configuration files. The order cannot be reversed. If the configuration file is deleted first, the service may still be running in memory and will not disappear until the next restart.
In Linux-like systems, user-level service units may be located in the user’s service configuration directory. You need to use the corresponding service management commands to stop, disable, and delete them. After processing, use the system’s service list command to confirm that the relevant entries have disappeared.
6. Step 5: Verify Uninstallation Results
After uninstallation is complete, confirm that there are no residuals through the following checks.
6.1 Command Check
Confirm that the relevant command can no longer be found in the system:
which <service_name>which <old_service_name>
If the command returns an empty result or a “not found” message, it means the executable file is no longer in the search path. If the command still exists, check its actual path to determine if it comes from another installation location.
6.2 Port Check
Services usually listen on local ports when running. After uninstallation, these ports should be released. You can confirm this using the system’s port viewing tool:
<port_check_command> -i :<default_port>
If the port is still occupied, it means the process may not have exited completely, or another program is using the port. Further troubleshooting is needed based on the process information.
6.3 Directory Check
Re-list the user’s home directory and candidate installation directories to confirm that all related paths have been deleted. This step can reveal older version directories missed in previous steps.
7. Common Issues and Handling Suggestions
Issue 1: The stop command is not found.
This usually means the command name was never installed, or the executable file has already been deleted. You can skip directly to the next step without repeating the execution.
Issue 2: Directory deletion prompts that it is in use.
This indicates that a process is still running. Recheck the process list and terminate the related process before deleting.
Issue 3: The service reappears after a restart.
There is a high probability that the system startup items were not cleaned up. Go back to Step 4, check the user-level startup item directory, and confirm that the corresponding service has been unregistered.
Issue 4: Concerns about credential leaks.
Do not just delete the configuration files. You should revoke the old keys on the corresponding service provider’s platform and generate new credentials. Deleting local files only eliminates local residuals and cannot invalidate already exposed credentials.
8. Environment Preparation Before Redeployment
If you need to redeploy after uninstallation, it is recommended to complete the following checks first to prevent interference between old and new versions.
First, confirm network connectivity. You can request a stable, accessible public address to check the returned status code:
curl -I https://<accessible_public_test_address>
A successful status code or redirect status code indicates that the external network is generally available. In an enterprise network, you also need to confirm whether the proxy configuration is correct.
Second, confirm the runtime environment. According to the service requirements, install the corresponding version of the runtime and package manager, and use the version viewing command to confirm the installation result. If the version does not meet the requirements, upgrade the runtime first before installing.
Third, confirm the installation path and configuration path. The path of the new version should be distinct from the cleaned old path to prevent the new installation from misreading the old configuration or the old configuration overwriting the new settings.
Fourth, keep a record of the uninstallation. Record the commands executed in each step, the paths deleted, and the credentials revoked to facilitate future troubleshooting or prove that the operation has been completed.
9. Summary
Completely uninstalling a local AI agent service requires handling four levels simultaneously: processes, programs, user data, and system startup items. By following the sequence of stopping first, then deleting the program, then cleaning up data, and finally checking startup items, you can avoid issues such as locked files, service restarts, and leftover credentials. Confirming the results with commands or directory checks after each step keeps omissions to a minimum. Content involving keys should be revoked on the corresponding platform, as deleting local files does not invalidate exposed credentials.
