Table of Contents
This practical guide explains how to edit configuration files in ubuntu with clear steps and useful context. It also covers common requirements, potential problems, and the details that can help you get better results.
To change the configuration, you need to open the file with a text editor and edit the file. The following article describes several ways to edit configuration files in Ubuntu. The steps described in this guide have been tested on Ubuntu 22.04, but should work on other versions of Ubuntu as well.
Using Gedit Editor
Gedit is the default text editor of the GNOME desktop environment. It supports tabs so you can open different files in multiple tabs. Gedit Editor is a simple and easy text editor compared to other available text editors.
To edit the configuration file in a text editor, launch Terminall by pressing Ctrl+Alt+T . Then type the command below with sudo privileges:
$ sudo gedit /path/to/filename
Replace /path/to/filename with the actual path of the configuration file you want to edit. When prompted for a password, enter the sudo password.
The following example edits the file /etc/resolv.conf

Gedit Editor is like Notepad editor in Windows operating system. As soon as the editor window opens, you can start typing or editing without entering any mode. When you're done editing, press Ctrl + S to save the file.

Using the Nano Editor
Nano is the simplest and most powerful built-in editor in many Linux distributions. You don't need to learn the Nano editor before using it, and you don't need to remember the commands either. They are displayed at the bottom and can be activated with the Ctrl key. For example, to save the file, press Ctrl+O.
To edit any configuration file, simply open a Terminal window by pressing Ctrl+Alt+T . Navigate to the folder containing the file. Then enter nano followed by the name of the file you want to edit.
$ sudo nano /path/to/filename
Replace /path/to/filename with the actual path of the configuration file you want to edit. When prompted for a password, enter the sudo password.

You can now edit and make changes in the configuration file using the Nano editor.

After editing, press Ctrl+O to save and Ctrl+X to exit the editor.
Using the Vim Editor
The Vim or Vi editor also comes pre-installed with most Linux distributions. It has no prompts or display controls, which can be a bit more difficult for beginners. However, once you get the hang of the basics, you'll find Vim a quick and powerful editing tool. Using Vim, you can edit and view multiple files in one session.
To open a file in the Vim editor, open a Terminal window by pressing Ctrl+Alt+T . Then enter vi with sudo privileges followed by the name and file path as follows:
$ sudo vi /path/to/filename
Replace /path/to/filename with the actual path of the configuration file you want to edit. When prompted for a password, enter the sudo password.

Then edit the file with the Vim editor. Note that when the editor opens, you will enter Command mode. Here are some steps to edit files in Vim editor:
- To edit a file, press I from the keyboard to enter Insert mode, where you can make edits just like a regular editor.
- When finished editing, exit this mode by pressing Esc. It will bring you back to normal mode.
- To save the file, type :w in Command mode
- To exit the editor, type :q in Command mode
- To combine the above actions, type :wq to save and exit simultaneously.

Conclusion
Understanding Ubuntu makes it easier to compare options, avoid common mistakes, and apply the information in this guide more effectively. Review the relevant requirements before making changes or choosing a solution.
FAQ
How do you edit configuration files in ubuntu?
Follow the steps in this guide in order, confirm the required settings or tools, and verify the result before making additional changes.
Is it safe to edit configuration files in ubuntu?
It is generally safe when you follow the recommended instructions, use trusted tools, and avoid changing settings you do not understand.
What should you do if the process does not work?
Recheck the requirements, restart the device or application when appropriate, and review each step for missed settings or compatibility issues.
Reader Comments 0
Sign in with email or Google to join the discussion.