Setting Terminal Encoding to UTF-8 on macOS and Linux
When working with certain development tools, such as CocoaPods for iOS and macOS projects, it’s important to make sure that your terminal is set to use UTF-8 encoding. If the encoding is not set properly, you may encounter an error message similar to this one:
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
This warning message is telling you that the CocoaPods dependency manager for iOS and macOS projects requires the terminal to be set to use UTF-8 encoding. This article will provide you with the steps to properly set your terminal encoding to UTF-8.
When working with certain development tools, such as CocoaPods for iOS and macOS projects, it’s important to make sure that your terminal is set to use UTF-8 encoding. This can be easily accomplished by editing your system’s shell profile file.
Step 1: Open the Terminal
Open the Terminal on your machine.
Step 2: Edit the profile file
If you are running macOS and using zsh shell, In the terminal, type the command nano ~/.zshrc
and press enter. This will open the .zshrc
file in the nano text editor. If you are running Linux or macOS and using bash shell, In the terminal, type the command nano ~/.bashrc
and press enter. This will open the .bashrc
file in the nano text editor.
Step 3: Add the UTF-8 Encoding Line
Scroll to the bottom of the file and add the following line:
export LANG=en_US.UTF-8
This line sets the locale language to US English and uses UTF-8 encoding.
Step 4: Save and Exit
Press Ctrl + O
to save the file, then press Ctrl + X
to exit the editor.
Step 5: Apply the Changes
Type the command source ~/.zshrc
or source ~/.bashrc
and press enter to apply the changes.
Step 6: Restart the terminal
You might need to restart the terminal for the changes to take effect or alternatively you can open a new terminal. Or you can restart your computer.
That’s it! You’ve successfully set your terminal to use UTF-8 encoding on macOS and Linux for both zsh and bash shell. Your terminal is now ready to work with development tools that require UTF-8 encoding. Please be aware that if you change your shell in the future, this change might be undone, so you might need to reapply the instructions.