Most of the computer programs we use—whether office suites, web browsers, even video games—are configured via menu interfaces. It has almost become the default way we use our machines.
But some programs require you to take a step beyond that. Instead of menus, you must edit a text file for the software to run as you wish.
These text files configure the software and are—unsurprisingly enough—called “config files”. If you want to enhance your computer knowledge you will need to know what a config file is and how to edit one.
What Are Config Files?
Before we get into the technical nitty-gritty, let’s first define what a configuration file is.
Config files are essentially editable text files that contain information required for the successful operation of a program. The files are structured in a particular way, formatted to be user configurable.
While some configuration is hard coded into software, settings that you can change are included in config files.
Surprisingly, there’s no defined standard on how config files should work, or what they should look like. It’s entirely up to the whim of the developer of the program.
Linux users will be particularly familiar with config files as many basic maintenance tasks require you to edit them. Tweaking the Raspberry Pi
often relies on editing config files. This might be to specify a wireless network to connect to or set the amount of RAM for graphics.
However, config files are not exclusive to Linux. There are times when you may have to edit them in Windows or macOS.
How to Find and Edit Config Files
Some config files are structured in a format of the developer’s own design. Others use widely known standards used to structure data, like:
- YAML (YAML Ain’t Markup Language)
- XML (eXtensible Markup Language)
Some programs load the information stored in their config files when they start. Meanwhile others periodically check the config file to see if it has been changed.
Whatever config file you want to edit it’s smart to make a copy of it before you make any changes. This way, if something goes wrong, you can restore the copy and start again!
Now, let’s take a look at a real-world config file. As we mentioned earlier, they come in all different shapes and sizes. One config file you’re almost certainly familiar with is the hosts file. Windows, Mac, and Linux all use this to manually map IP addresses to hostnames.
Windows Config Files
Windows users will find the hosts file in c:windowssystem32driversetc.
You can open it by double-clicking the mouse and selecting Notepad from the list of suggested apps. This is all you need to view and edit config files like hosts. However, several alternatives are available—see below for details.
With the file open you will see that it uses whitespace (literally spaces and tab stops) to separate elements.
Each hostname has its own line, followed by a tab stop and the IP address. Furthermore, the hosts file allows the user to add annotations and comments, which all begin with a hash symbol.
Linux Config Files
On Linux, you’ll find the hosts file in /etc/. This can be opened in Gedit, or a command line text editor such as nano or vim. In most cases your Linux distro will have one or all of these preinstalled.
Some programs store the config file in the home directory, with a period at the beginning of the filename. These config files sometimes have the file extension .rc and we refer to them as “dotfiles”.
Config Files in macOS
Like Linux, the hosts file can be found in /etc/ on macOS.
Mac users will know that BBEdit is the default, preinstalled text editor. This makes it ideal for editing config files in macOS. However, as with Linux, command line editors vim and nano are also available.
Apps for Safely Editing Config Files
So, now we know what config files are used for, let’s talk about how we can edit them.
To do this, you’re going to need a text editor. Avoid word processors; these can add formatting to the file which would prevent them from being read correctly.
Native text editors are available, as mentioned. However, for extra functions, third party text editors are also available:
Download: Notepad++ for Windows (Free)
Download: Atom for Windows, macOS, Linux (Free)
Download: Sublime Text Editor for Windows, macOS, Linux (Free evaluation)
So many text editing tools are available for every platform that it is hard to recommend a single app. Linux users can also check our list of Linux text editors
. Meanwhile this round up of text editors for macOS
should help Apple computer owners.
When you edit a config file, it’s important to ensure you follow the conventions of it. This can be worked out just by looking at it. Some config files, like the hosts file, will explain these conventions to you in commented out lines. Others will force you to read some documentation, or a couple of blog posts.
Finally, if the config file you edit has a JSON or XML format, consider a text editor with syntax highlighting. Notepad++ and Atom are both good options here. Syntax highlighting will improve your accuracy by showing you when you’ve made a mistake.
Other Places You Can Find Config Files to Edit
If you’re interested in exploring config files further, you’ll find them in all sorts of applications and platforms. There is more to config files than specifying which websites and IP addresses to block!
Beyond the hosts file, you’ll find config files in video games. These are often used to define and control things like keymappings.
Meanwhile, some config files can be used to cheat. This was the case in the original Deus Ex game on PC. These days, cheating is far more difficult and often not worth the effort unless enabling an official cheat mode.
Web applications also use configuration files for customization.
What If Your Config Edit Doesn’t Work?
Problems associated with editing config files tend to fall into two camps: permissions and user error.
Issues with config files caused by permissions issues are down to system integrity. You’re unable to save changes because you’re editing as an ordinary user. To prevent accidental misconfiguration, many config files are only editable by those with administrator-level privileges.
Fixing this is easy:
- On Windows, right-click the text editor, and select Run as administrator
- On macOS and Linux, try escalating your privileges with the sudo command. So, if you were editing your hosts file, run sudo nano /etc/hosts
(Note that if you specified a different filename or location, you would effectively create a config file in the terminal.)
When the problem is user error, it means it’s your fault. Check that you haven’t made any typos, and that you’ve followed the conventions of the config file.
While it may seem obvious, a simple spelling mistake can render your entire file useless. Before committing to your changes and saving the file remember to:
- Check the change you made
- Ensure you left a comment
Also be sure to close the config file before trying to run the software you’re attempting to configure.
Config Files Are Important
More than important, they’re an essential part of using Linux. Knowing how to properly edit them can help you considerably.
While you can edit many config files, be sure to make a copy of the file before making any changes. That way, you can revert to the original if something goes wonky.