Configuration files contain the information required to control the operation of a program. For Linux users especially Linux administrators, they must know how to edit these files and perform the basic configuration. Configuration files are stored in /etc subdirectories as a text file and can be edited using text editors. Some of the examples of config files are host.conf, hosts. resolv.conf, networks, syslog.conf etc. in Linux based operating systems.

To make any configuration changes, you have to open and edit the file. In this article, I will describe some ways that you can use to edit config files in Ubuntu 18.04 LTS.

  • Using Gedit Editor
  • Using Nano Editor
  • Using Vim Editor
  • Using Gvim Editor
  • Using Emacs Editor

Now let’s take a look at these text editors. By using these editors, you can easily edit any config file.

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. It is the simpler and easier text editor as compared to other available text editors.

To edit a config file in text editor, launch Terminal by pressing Ctrl+Alt+T key combinations. Then type the below command as sudo:

$ sudo gedit /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.

Example: editing of the /etc/resolv.conf file

Edit file with gedit

It is like the notepad editor in Windows OS. As soon as the editor window opens, you can start typing or editing without entering in any mode. Once you have done with the editing, press Ctrl+S to save the file.

Editing configuration file with GEdit

Using Nano Editor

Nano is the simplest and the powerful built-in editor in the many Linux distributions. You do not have to learn the Nano editor before using it and also there is no need to remember the commands. They are displayed at the bottom and can be triggered with the Ctrl key. For instance to save a file, press Ctrl+O.

To edit any config file, simply open the Terminal window by pressing the Ctrl+Alt+T key combinations. Navigate to the directory where the file is placed. Then type nano followed by the filename that you want to edit.

$ sudo nano /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.

Now you can edit and make changes in the config file using Nano editor.

Edit config file in nano editor

Once you have done editing, press Ctrl+O to save and Ctrl+X to exit the Editor.

Using Vim Editor

Vim or Vi editor also comes pre-installed with most Linux distributions. It has no visible prompts or control that can be a little harder for beginners. However, once you learned it, it is the more quick and powerful tool for editing. Using Vim, you can edit and view multiple files in one session.

To open a file in Vim editor, open the Terminal window by pressing the Ctrl+Alt+T key combinations. Then type vi as sudo followed by filename along with the file path like:

$ sudo vi /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.

Edit file in Vi editor

Then edit the file using Vim editor. Note that when the editor opens, you enter in command mode. Here are the few steps to edit a file in Vim editor:

  • To edit the file, Press I from keyboard to enter into insert mode, here you can do editing just like the normal editor.
  • When done with editing, get out of this mode by pressing Esc. It will return you to normal mode.
  • To save the file, type :w in command mode
  • To quit the editor, type :q in command mode
  • To combine the above actions type :wq to save and quit simultaneously.

Using Vi File Editor on Ubuntu

Using Gvim Editor

Gvim is a Vim editor with a graphical user interface. To install Gvim, launch Terminal by pressing Ctrl+Alt+T. then type the below command in Terminal to start the installation.

$ sudo apt-get install vim-gnome

Install Gvim

Once done with the installation, you can open and edit any config file in it. Type the below command with sudo in Terminal to open any config file in Gvim:

$ sudo gvim /path/to/filename

Edit file in GVim

Press I to enter in insert mode where you can edit the file.

GVim file editor

In Gvim editor, you can do various functions using the toolbar just like the any normal GUI application like saving the file, undo, redo, finding a keyword, etc.

Using Emacs Editor

Emacs is also a text editor but it is not a built-in editor. You have to manually install it using the Ubuntu Terminal. It has so many features including a built-in web browser, calculator, calendar, Terminal, etc.

To install Emac utility, launch Terminal by pressing Ctrl+Alt+T key combinations. Type the below command in Terminal as sudo:

$ apt-get install emacs

Install Emacs editor

Once done with the installation, you can open and edit any config file in it.

To open a config file using emacs editor, type emacs followed by filename along with the file path in the below syntax:

$ sudo emacs /path/to/filename

Replace /path/to/filename with the actual file path of the configuration file that you want to edit. When prompted for a password, enter sudo password.

Editing text files in Emacs

Edit the file as normal and save it using toolbar.

Emacs editor on Ubuntu Linux

You can also open config file in bash instead of a separate window.

Type the following command as sudo in Terminal:

Using emacs shell mode

Edit the file as a normal text file. Then press Ctrl+X and Ctrl+C to save the file. When it prompts for saving the file, press y to save and quit the editor.

Emavs in shell mode

So these were some simple editors you can use to easily and safely edit config files in your Ubuntu operating system.

How to Edit Config Files in Ubuntu