Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I add line numbers to Emacs?

Please explain, I'm an absolute beginner.

share|improve this question
up vote 7 down vote accepted

If you're running it in default mode, it's in the menu: Options > Show/Hide > Line Numbers. Then Options > Save Options to save it for future sessions.

If you're running it in a terminal (emacs -nw), then it's M-x line-number-mode. M- is usually the Windows key, but may be Alt, or you can press Esc followed by x.

(Edit: The above only affects the mode line. For line numbers in the margin, you want M-x linum-mode, or more likely (setq global-linum-mode t) in your ~/.emacs.)

share|improve this answer
That only displays the current line number in the mode line – Florian Diesch May 6 '11 at 19:44
@Florian: Good catch. I added the instructions for linum-mode to the answer. – geekosaur May 6 '11 at 19:48
Ok, you've been faster - deleted my answer – Florian Diesch May 6 '11 at 19:55
(setq global-linum-mode t) is not working when I add this line to .emacs.d/init.el, I just change it to(global-linum-mode t) and it works. Any reasons why? – ZijunLost Dec 28 '15 at 2:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.