This guide shows how to fully remove Chef Automate, Chef Infra Server and the Chef client tools from a Linux host. It explains what each command in the example above does, gives a safer corrected order, covers backups and leftover files, and ends with checks that confirm the host is clean.
$ systemctl stop chef-automate
$ pkill chef-automate
$ rm -rf /hab
$ userdel hab
$ chef-server-ctl uninstall
What the commands above do
Chef Automate 2.x runs as a set of Habitat services under /hab, managed by one systemd unit named chef-automate. A standalone Chef Infra Server is an Omnibus package installed under /opt/opscode and managed with chef-server-ctl. The example above mixes both products, so it helps to know what each line affects.
| Command | Effect | What it leaves behind |
|---|---|---|
systemctl stop chef-automate | Stops the Automate systemd unit and its Habitat supervisor | The unit stays enabled and starts again after a reboot |
pkill chef-automate | Kills any remaining chef-automate processes | hab-launch, hab-sup and service processes with other names |
rm -rf /hab | Deletes all Habitat packages, service data and configuration | The systemd unit file and the chef-automate binary |
userdel hab | Removes the hab user | The hab group, if other members still use it |
chef-server-ctl uninstall | Stops Infra Server services and removes the application | All data in /var/opt/opscode, the configuration and the chef-server-core package |
Note: Every command here needs root. Run them as root or with sudo. The $ prompt in the example above suggests a normal user, which makes most of them fail with permission errors.
Back up before you remove anything
All of these steps destroy data for good. If there is any chance you will need the cookbooks, node data, compliance reports or user accounts later, take a backup first and copy it off the host.
# Chef Automate: creates a backup under /var/opt/chef-automate/backups by default
sudo chef-automate backup create
sudo chef-automate backup list
# Standalone Chef Infra Server: writes a tarball under /var/opt/chef-backup
sudo chef-server-ctl backup
# Copy the backups somewhere safe before uninstalling
sudo rsync -a /var/opt/chef-automate/backups/ backup-host:/srv/chef-automate-backups/
sudo rsync -a /var/opt/chef-backup/ backup-host:/srv/chef-server-backups/Code language: PHP (php)
Backup locations can be changed in configuration. If the paths above are empty, check the output of the backup command for the real location.
Corrected version of the commands above
Chef Automate has its own uninstall subcommand. It stops the services, removes the systemd unit and deletes Automate data, so you do not need to kill processes or delete /hab by hand. If Chef Infra Server was deployed with Automate (chef-automate deploy --product automate --product infra-server), it runs as a Habitat package, and chef-automate uninstall removes it too. In that setup chef-server-ctl lives under /hab, so it stops working once /hab is deleted. That is why the last line of the original fails.
# 1. Uninstall Chef Automate (and any Infra Server deployed with it)
sudo chef-automate uninstall
# 2. If the systemd unit is still present, stop, disable and remove it
sudo systemctl stop chef-automate 2>/dev/null
sudo systemctl disable chef-automate 2>/dev/null
sudo rm -f /etc/systemd/system/chef-automate.service
sudo systemctl daemon-reload
# 3. Kill any leftover Habitat processes
sudo pkill -f hab-launch
sudo pkill -f hab-sup
# 4. Remove Habitat data, user and group (only if nothing else on the host uses Habitat)
sudo rm -rf /hab
sudo userdel hab 2>/dev/null
sudo groupdel hab 2>/dev/null
# 5. Remove the chef-automate binary you downloaded
which chef-automate && sudo rm -f "$(which chef-automate)"Code language: PHP (php)
chef-automate uninstall asks for confirmation. On a host you are about to rebuild, the manual steps 2 to 5 only act as a safety net. If the uninstall finished cleanly, most of them do nothing.
Note: Do not delete /hab or the hab user on a host that runs other Habitat services. They share the same supervisor and package store.
Uninstall a standalone Chef Infra Server
chef-server-ctl uninstall removes the running application, but by design it keeps the data. To remove everything, wipe the data with cleanse, uninstall, remove the package, then delete the leftover directories.
- If Chef Manage (the web UI) is installed, remove it first:
sudo chef-manage-ctl cleanse, then remove thechef-managepackage. - Run
sudo chef-server-ctl cleanse. This stops services and deletes data, logs and generated configuration. It asks for confirmation before it continues. - Run
sudo chef-server-ctl uninstallto stop the runit supervisor and remove the application. - Remove the package:
sudo apt-get purge -y chef-server-coreon Debian or Ubuntu, orsudo dnf remove -y chef-server-coreon RHEL-family systems. - Delete what is left:
sudo rm -rf /opt/opscode /var/opt/opscode /var/log/opscode /etc/opscode. - Remove the service accounts the package created, if they still exist:
sudo userdel opscodeandsudo userdel opscode-pgsql.
sudo chef-server-ctl cleanse
sudo chef-server-ctl uninstall
sudo apt-get purge -y chef-server-core # or: sudo dnf remove -y chef-server-core
sudo rm -rf /opt/opscode /var/opt/opscode /var/log/opscode /etc/opscode
sudo userdel opscode 2>/dev/null; sudo userdel opscode-pgsql 2>/dev/nullCode language: PHP (php)
Remove Chef Infra Client and Chef Workstation
Nodes that registered with the server still have the client installed and a node and client object on the server. Delete those objects from a workstation before you remove the server, then uninstall the client on each node. See the knife command line reference for more options.
# From the workstation, while the server is still up
knife node delete web01 -y
knife client delete web01 -y
# On each node: remove Chef Infra Client
sudo apt-get purge -y chef # Debian/Ubuntu
sudo dnf remove -y chef # RHEL family
sudo rm -rf /opt/chef /etc/chef /var/chef /var/log/chef
# On a Linux workstation: remove Chef Workstation
sudo apt-get purge -y chef-workstation # or: sudo dnf remove -y chef-workstation
sudo rm -rf /opt/chef-workstation
# Optional: removes your knife config and keys
rm -rf ~/.chefCode language: PHP (php)
On Windows, remove Chef Infra Client or Chef Workstation from Apps and Features, then delete C:\chef and C:\opscode if they remain.
Verify the host is clean
# No Chef, Habitat or Omnibus processes should be listed
ps -ef | grep -E 'hab-|chef|opscode|runsv' | grep -v grep
# Ports 80 and 443 should no longer be held by nginx from Chef
sudo ss -tlnp | grep -E ':(80|443)\s'
# No units or directories left behind
systemctl list-unit-files | grep -Ei 'chef|runsvdir'
ls -d /hab /opt/opscode /var/opt/opscode /opt/chef* 2>/dev/null
# Service accounts gone
id hab; id opscodeCode language: PHP (php)
Each command should return nothing, or no such user for the id checks. If something still shows up, stop the process or unit, then remove the remaining path.
Common errors and fixes
| Symptom | Cause | Fix |
|---|---|---|
chef-server-ctl: command not found | /hab was deleted first, and Infra Server was deployed through Automate | Nothing more to uninstall with chef-server-ctl. Remove the leftover systemd unit and directories by hand |
rm: cannot remove '/hab/...': Device or resource busy | Habitat processes still running, or a mounted path under /hab | Stop the processes with pkill -f hab-, check with mount | grep /hab, then retry |
userdel: user hab is currently used by process | Supervisor or service processes still own files | Kill the processes listed, then run userdel again |
| Automate starts again after a reboot | The systemd unit was stopped but not disabled or removed | Run systemctl disable chef-automate, remove the unit file and run daemon-reload |
| Reinstall fails because the port is in use or old data is present | Old nginx or /var/opt/opscode data left behind | Run the verification checks and remove whatever is left |
Frequently asked questions
Does chef-server-ctl uninstall delete my Chef Infra Server data?
No. It stops the services and removes the application, but it leaves data and configuration in place. Use chef-server-ctl cleanse to wipe the data, then remove the chef-server-core package.
How do I uninstall Chef Automate cleanly?
Run sudo chef-automate uninstall. It stops the services, removes the systemd unit and deletes Automate data. Afterwards, check that no hab-sup processes and no /hab directory remain.
Is it safe to run rm -rf /hab?
Only if no other Habitat-managed services run on the host. /hab holds every Habitat package and all service data, so deleting it removes all of them.
Do I need to remove nodes from the Chef server before uninstalling it?
It is not required if the server is being destroyed. Still, deleting the node and client objects with knife first, and uninstalling the client on each node, stops nodes from failing their scheduled chef-client runs against a server that no longer exists.
Can I reinstall Chef Automate or Infra Server on the same host afterwards?
Yes, once the verification checks show no leftover processes, units, directories or users. Leftover data in /hab or /var/opt/opscode is the most common reason a reinstall fails.
Related tutorials
- Chef Tutorials: knife command line reference
- What is Chef and use cases of Chef?
- More Chef tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals