How to edit configuration files in Ubuntu

Configuration files contain information necessary to control the operation of the program. Linux users, especially Linux administrators, need to know how to edit configuration files to maintain Ubuntu server or desktop. Configuration files on Ubuntu are stored in subdirectories of the /etc directory as text files and can be edited with a text editor. Some examples of configuration files are /etc/hosts, host.conf, hosts. resolv.conf, /etc/networks, syslog.conf , etc. in Linux-based operating systems.

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

How to edit configuration files in Ubuntu Picture 1

 

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.

How to edit configuration files in Ubuntu Picture 2

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.

How to edit configuration files in Ubuntu Picture 3

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

How to edit configuration files in Ubuntu Picture 4

 

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.

How to edit configuration files in Ubuntu Picture 5

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:

  1. To edit a file, press I from the keyboard to enter Insert mode, where you can make edits just like a regular editor.
  2. When finished editing, exit this mode by pressing Esc. It will bring you back to normal mode.
  3. To save the file, type :w in Command mode
  4. To exit the editor, type :q in Command mode
  5. To combine the above actions, type :wq to save and exit simultaneously.

How to edit configuration files in Ubuntu Picture 6

4 ★ | 2 Vote

May be interested

  • Why is Ubuntu LTS preferred over regular distros?Why is Ubuntu LTS preferred over regular distros?
    ubuntu is one of the most widely used linux distributions among software developers and other content creators. ubuntu is also used for many servers around the globe.
  • How to install Ubuntu in parallel with Windows using USBHow to install Ubuntu in parallel with Windows using USB
    installing ubuntu in parallel with windows 7 and 8 with usb will help users not to waste time writing files to disk, running on many different computers.
  • How to edit PDF files with Google DocsHow to edit PDF files with Google Docs
    how to edit pdf files with google docs. pdfs are known as picky software files because only specialized software can read and edit them. but if you want to edit basic, not too complicated and require fast, easy to use, you can use google docs to edit.
  • What's new in Ubuntu 18.04 LTS just released?What's new in Ubuntu 18.04 LTS just released?
    ubuntu 18.04 lts code-named bionic beaver has just been officially launched on april 26th. this version is canonical's up to 5 year support period.
  • The simplest way to edit PDF filesThe simplest way to edit PDF files
    if you've ever tried editing pdf files, you've surely discovered that it's not as simple as editing microsoft office documents. some people still have to spend a lot of time and effort making a new pdf when they cannot edit the old pdf file. in this article, tipsmake will guide you through the simplest ways to edit pdf files so you don't have to be confused when performing tasks related to this format anymore.
  • How to Migrate from Windows to UbuntuHow to Migrate from Windows to Ubuntu
    when migrating from windows to ubuntu, there are a few things you might need to reflect over, like how to cope the new system, the new interface, and how to adapt to ubuntu in general, and of course, how to transfer your personal files...
  • How to create and edit ISO files with UltraISOHow to create and edit ISO files with UltraISO
    ultraiso is a tool that helps users create, edit and convert iso image files of cds and dvds. how to create and edit iso files with ultraiso helps users to copy to a drive easily, add, delete or edit iso files with higher specifications.
  • How to Edit APK FilesHow to Edit APK Files
    this wikihow teaches you how to edit the contents of an apk file. to edit the files inside, you'll need to decompile (and then recompile) the package using apktool on a computer. editing apk files requires knowledge of java, as well as the...
  • How to edit PDF files with Word 2016How to edit PDF files with Word 2016
    how to edit pdf files with word 2016. previously, to edit pdf files we need specialized pdf processing software, but word 2016 and onwards has built-in very powerful pdf editing function, if if you do not know this feature then follow up
  • How to Edit Ubuntu RepositoriesHow to Edit Ubuntu Repositories
    has a website told you to add a ubuntu repository? then follow these steps. any changes require you to be in the 'sudo' user group and have your password handy. open the ubuntu software centre.