Tuesday, 12 November 2013

Updating Coreutils (Homebrew)

Coreutils (GNU) are a set of basic utilities that most unix-like operating systems come with. Although OS X comes with most of them, some are very outdated and lack features we might want to use. One example of a feature we want is using the ls command (lists directory contents) to show colours based on the type of file.

Prerequisite

This tutorial is based on the assumption homebrew is installed

This tutorial will be used with homebrew but can be applied to other package managers (such as MacPorts) following the basic structure:

  • Install Coreutils
  • Change PATH environment variable to check coreutils directory first
  • Restart terminal

This tutorial was done with the following versions:
  • Homebrew (November 2013)
  • Mavericks (10.9)

Installation

1. Open up your preferred terminal

2. Copy this into your terminal and press enter
brew install coreutils

coreutils installing


3. Run the following command 
gls --color

Pretty colors !


What you're doing here is running the "ls" command with the option --color. Because Homebrew doesn't want to be destructive to your system files and overwrite the ones that come with OSX, it sticks them in another folder and creates an alias of each command with the character "g" in front of it so you can access it.

If you're comfortable using the updated coreutils like this then you can stop this tutorial. If you're like me and wish to use them instead of writing "g" in front of the command every time, continue.

Configuration 


1. Run the following command
echo export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" >> ~/.bash_profile

2. now run another command
echo export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH" >> ~/.bash_profile

Adding environment variable to your .bash_profile


What we've done here is basically told the shell to look in the directory of the updated utils before anything else. We've also told it to look in the man directory (for man pages) of the updated utils before anything else. For further explanation of the above command I encourage you to look into the following things.

  • echo
  • environment variables
  • redirection 
  • .bash_profile

3. Close and Open your terminal for the changes to take effect

4. Enter the following command
man ls  
5. Scroll to the bottom of the page (ctrl + g) and see that you're running an up-to-date version.

GNU Coreutils 8.21

End Notes

Check out some other tutorials about diving into the terminal side of things in OS X.



No comments:

Post a Comment