So, I recently started using emacs as a text editor, instead of vi. It didn’t seem easy to get things up straight at start. But gradually I understood why many experienced developers prefer emacs: it is highly customisable and extensible.

vi gives you easy to use command to show line numbers, :set nu and you are done.

That is not the case with emacs, and hence this blog post. You need to install linum package and enable linum-mode for this.
Make sure you have the latest version of emacs, at the time of writing 24.3,
so that you have emacs package manager ready. Add marmalade and melba to the package
archive list by adding the following to your ~/.emacs.d/init.el.

1
2
3
4
5
6
(require 'package)
(add-to-list 'package-archives'
("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives'
("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

Now list the packages using M-x list-packages command.

You should get a list of packages like this.

Next locate linum package using Ctrl-s command.
You may have to repeatedly use Ctrl-s to get the right package.
It would say display line numbers in the right margin.

Select and install that using arrow keys and return key.
You can enable linum-mode right away using M-x linum-mode command.

References: