How to Permanently Save htop Settings in Ubuntu
This article confirms that you can save htop configuration changes permanently on Ubuntu and explains the specific steps to ensure they persist. By default, htop is designed to write settings to a configuration file upon exit, but user permissions and directory structures often interfere with this process. The following sections detail where the configuration is stored, how to apply changes correctly, and how to troubleshoot issues if settings reset after closing the application.
Understanding htop Configuration Storage
htop stores its configuration in a plain text file located in your
home directory. Specifically, the file path is
~/.config/htop/htoprc. When you modify settings within the
htop interface, such as changing color schemes, meter layouts, or column
displays, these changes are held in memory until the program closes.
Upon a proper exit, htop attempts to write the current state of these
settings to the htoprc file. If this file exists and is
writable, your changes will be loaded automatically the next time you
launch the tool.
Properly Exiting to Save Changes
A common reason for lost configuration is an improper exit method. To
ensure settings are saved, you must exit htop using the built-in quit
command. Press the F10 key or the q key while
inside the application. These commands trigger the shutdown sequence
that includes writing the configuration file. If you close the terminal
window abruptly or kill the process using a system signal like
kill -9, htop cannot execute the save routine, and your
changes will be lost.
Handling Permission Issues
If you run htop with standard user privileges, it saves settings to
your user configuration directory. However, if you run htop using
sudo htop, it looks for the configuration file in the root
user’s home directory (/root/.config/htop/htoprc). Changes
made while running as root will not appear when you run htop as a normal
user. To maintain consistent settings, avoid using sudo unless necessary
for viewing specific processes. If you must run as root, configure the
settings while in sudo mode so they save to the root configuration
file.
Manually Editing the Configuration File
You can also edit the configuration file directly if the interface
changes are not sticking. Open the file using a text editor like nano
with the command nano ~/.config/htop/htoprc. If the
directory or file does not exist, run htop once and exit properly to
generate it. You can modify values such as color_scheme or
sort_key directly in this file. Ensure you save the file
and exit the editor correctly. Once edited, the next time you launch
htop, it will read these permanent values from the disk.