Learning how to edit config files on Ubuntu is essential to change program settings.
Several applications, services, and components can be handled with the config files, resulting in complete control over your Ubuntu system.
This guide details how to edit config files on Ubuntu using various approaches. In addition, we will provide you with a simple summary of each approach for better understanding and then proceed with the steps.
What is the need for editing Config Files on Ubuntu?
Even with the interactive GUI, an individual wouldn’t completely fine-tune the behavior of their Ubuntu system, which is where editing config files comes in. For this purpose, here are key reasons why editing config files are crucial:
- Complete control over personalization.
- Responsible for Performance Optimization.
- Can modify System-wide Policies and Permissions.
- Manage Hardware and Device Configurations.
Various Approaches to Edit Config Files on Ubuntu
Not every approach is reliable and easy. Hence, we have provided you with the most used and reliable approaches to ease the process of editing config files on Ubuntu.
1. Command Line Editors
As the name suggests, command line editors can be accessed directly from the Terminal or command line interface. The advantage of these editors is they are efficient and easy to use.
Many popular command line editors exist, but Nano and Vim are the most commonly used ones.
Note: Before we start, we suggest using the Terminal as root to avoid the “permission denied” error. Also, make sure the file you want to edit comes with all ‘rwx’ permissions.
How to edit config files on Ubuntu using Nano?
Start with opening the Terminal by pressing “
Ctrl + Alt + T“.
Make sure to remember the path and name of the file you’re configuring. Then, change the current directory to the config file’s directory, using the “cd” command.
For example, if your config file is in the directory named ‘etc’, the command will look like this:
To open the config file using the Nano command line editor, the ‘sudo’ command is required to ensure you have the necessary permissions to edit system files.
For instance, if the config file you want to edit features the name ‘config.conf‘, type in the command:
sudo nano config.conf
Following the above steps, you will notice the ‘config.conf’ file open in the Nano editor. Now perform all the necessary modifications by navigating around using keys. Then, once done, press “
Ctrl + O” to save the file.
Once successfully saved, press “
Ctrl + X” to exit the Nano Editor. If you want to verify if the changes are made, use the ‘cat’ command followed by the file path:
The below image shows the final result if you have used Nano editor to edit the config files:
How to edit config files on Ubuntu using Vim?
To begin editing the config file, press “
Ctrl+Alt +T” to launch a new Terminal window and open the Terminal.
Remember the file’s name and path so you may switch the current directory to the configuration file’s directory. Use the “cd” command to carry out this action.
For instance, enter the command if your configuration file is in the directory ‘etc’:
Like the Nano editor, editing the config files using the ‘Vim’ editor requires the ‘sudo’ command. If the configuration file you wish to update has the name “config.conf,” enter the command:
sudo vim config.conf
Once the Vim editor is opened, navigate around using the arrow keys. To edit the config file, enter the edit mode by pressing the ‘i’ key. Doing so will display — INSERT — text at the bottom of the window.
After you modify the config file, press the ‘Esc’ key to return to command mode.
Now type “:wq” and press ‘Enter’ to save the changes you’ve made and exit Vim.
Once done with all modifications, you can use the ‘cat’ command followed by the file’s path to verify if the changes are made successfully:
Here is the final result if you have used Vim editor to edit the config files:
2. Graphical Text Editors
Graphical Text Editors on Ubuntu features a user-friendly interface for editing text files, including the config files. It is a great replacement for the command-line editors, as it doesn’t require understanding and learning commands.
There are many graphical text editors available for Ubuntu. However, we recommend “gedit”, as it is easy to use and reliable.
How to edit config files on Ubuntu using gedit?
Open gedit on your Ubuntu device by searching in the search bar and clicking on the gedit icon that appears to launch the text editor.
Once gedit is loaded, press “Ctrl + O“. Make sure to navigate to the correct directory where the config file is located. Then, click on the “Open” button after finding and selecting your desired config file.
Make modifications to the config file, and once done, press ‘Ctrl + S‘ to save the file.
You can reopen the file to verify the changes or use the ‘cat’ command on a Terminal:
Third-Party File Managers
These are some of the best approaches for editing config files on Ubuntu. If you’re confused about selecting the config file from the file selection dialog, we suggest trying Nautilus or PCManFM file managers in Ubuntu.
These file managers provide reliability for finding the config file and help prevent selecting the wrong config file’. Once you have found your file through the file manager, double-clicking on it opens it directly in gedit.
In this article, we have provided various methods for editing config files in Ubuntu. Command-line editors, like Nano and Vim, are ideal for more technical users. Alternatively, a graphical text editor like Gedit is user-friendly for editing configuration files.
We suggest you take a config file backup before editing, as improper modifications can lead to system instability or render your system inoperable. Moreover, you can use the copy/paste function as a form of backup as well.
If this guide helped you, please share it.