76

I used sudo apt-get install emacs to download emacs. I expected the command-line emacs to start when I ran emacs but instead the GUI emacs started.

How can I download the command-line emacs?

1
  • 3
    Please consider changing your accept from the highly unwise answer that falsely implies dragging in all of the X library dependencies of the ordinary emacs package is necessary, to one of those which answers your actual question by showing how to install a headless version of emacs without all those unnecessary dependencies. Nov 1, 2019 at 18:13

5 Answers 5

113

That would be emacs-nox I believe. This is the meta-package that currently points to emacs24-nox .

Description: The GNU Emacs editor (without X support)

So, just as before but with that package:

sudo apt-get install emacs-nox

or alternatively

sudo apt-get install emacs24-nox

For cases like this, where you wonder what's in what package, try this :

apt-cache search ^emacs 

then

 apt-cache show <whateverpackage>
6
  • 2
    "sudo apt-get install emacs24-nox" did work for me.
    – user103154
    Oct 25, 2013 at 11:57
  • Stephan - try emacs23-nox. Its still a big package at 26MB download/78MB on disk.
    – user207039
    Dec 26, 2013 at 1:42
  • 12
    This is closer to what I believe the accepted answer should be. Often Emacs is desired on servers which do not need the resource clutter of the full emacs distribution installed.
    – ctpenrose
    May 17, 2015 at 0:24
  • 3
    Installing nox required 7 dependencies for me on a fresh system. Without nox, it would've installed 122.
    – agweber
    Sep 24, 2015 at 15:24
  • 2
    It's too bad that this great big thing doesn't include a decent Editor. (Grinning, Running, and Ducking)
    – Warren P
    Dec 15, 2015 at 21:32
72

The command-line emacs is installed along with the GUI.
To run it, use the -nw option. An explanation from man emacs:

-nw, --no-window-system
Tell Emacs not to use its special interface to X. If you use
this switch when invoking Emacs from an xterm(1) window, display
is done in that window.

So run the following command to use emacs from the command-line:

emacs -nw

enter image description here

If you don't want to have to type emacs -nw, you could create an alias. Put the following line in your ~/.bashrc or ~/.bash_aliases:

alias emacs="emacs -nw"

You can add this alias in one line by using I/O Redirection::

echo alias emacs=\"emacs -nw\" >> ~/.bashrc
6
  • 13
    This answer only covers running non-X emacs. This does not explain how to download emacs that is only for command line. May 16, 2016 at 11:44
  • @user2943160 What do you mean? This answer starts out with the sentence "The command-line emacs is installed along with the GUI". We know from the question that the OP already knows how to install it. Sep 28, 2019 at 0:01
  • @JonBentley hello from your necropost comment. This answer still doesn't cover a non-windowed (that is, no support for system windowed operation) installation of emacs, though such a thing isn't particularly necessary given, yes, the rest of the content. Oct 4, 2019 at 22:41
  • @user2943160 This is a Q&A site, not a forum, so there is no concept of a "necropost". The value is in the question and the answers, not in the timing. I don't think the OP particularly cares whether or not there is no support for a windowed vesrion, so long as they can run it on the command line (and even if we interpret the question title in that way, a frame challenge would be valid given the OP's underlying objective). This answer is perfectly fine as it is in addressing the root of the question, and is a valuable alternative to the other options. Oct 7, 2019 at 0:12
  • 1
    This is a very poor answer, because when the ordinary emacs package is installed via apt on a headless system not normally used with X, it will not only unnecessarily install the X version of emacs, it will install all of the X client libraries that are dependencies of that - which is a huge amount of unnecessary installation. Nov 1, 2019 at 18:09
6

If possible, delete the old version of emacs, then reinstall the version without X. The * on the end of the command is important and will save you from a world of pain.

apt-get remove emacs*
apt-get install emacs-nox

You can also specify the version of emacs without X to install, such as emacs23-nox or emacs24.nox rather than installing the alias package.

Sure, you can mess with bash aliasing or pass in -nw, but when you use sudo, or emacs is summoned by git, you'll see that X window once again.

2
  • installing emacs-nox will remove the other package.
    – Adam
    May 6, 2017 at 12:41
  • In apt removing packages with wildcard * may cause serious problem on system If you don't read its output and just aggree with it.
    – EsmaeelE
    Apr 18, 2022 at 8:09
1

You already have installed it.

Just run emacs with:

emacs -nw
1

I think I accidentally downgraded a post without intending to. emacs -nw is the correct option.

I just get tired of the vi/emacs flame warz. If the original post didn't mention vi, then mentioning vi doesn't help.

Besides, emacs has a vi mode in it - viper-mode.

1
  • 1
    No, that is not the correct answer. The question is about installing a non-gui version, installing the huge gui version and all of its unecessary gui dependencies is not a reasonable solution, when in fact it's possible to do exactly what the question seeks. Jul 21, 2020 at 0:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .