So, I'm trying to set up emacs as a server but I'm having trouble getting it to work from the terminal. If I run emacs --daemon on some terminal I can connect to it if I run the emacsclient from that same terminal, but if I open a new terminal the emacsclient will not find the server. Things seem to work well if I run emacsclient from the launcher.

I am running

emacsclient -a '' -t

The client says:

emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

Any ideas of what could be happening?

I am using ubuntu 17.04 with gnome/i3 if that matters.


I used to have the same issue until I did:

alias e="emacsclient -t --socket-name=/tmp/emacs1000/server"

And now I just use this "e" alias to start emacsclient.

I haven't seen the issue since.

| improve this answer | |
  • This worked, how do I tell the server to start the /tmp/emacs1000/server ? (the first client is starting it for me) – Matías Guzmán Naranjo Sep 27 '17 at 18:04
  • Before running an emacsclient, I always first start the emacs server as emacs --daemon and it always starts listening on that /tmp/emacs1000/server socket automatically. I'm sure there's a less hacky way to do this that doesn't involve hardcoding the /tmp/emacs1000/server location in the e alias, and would always work no matter where the socket is created by the server (and that is probably how emacsclient is intended to work when invoked without the --socket-name option), but doing it this simple hackish way always worked for me. – izkon Sep 27 '17 at 18:23

Make sure you are using the same version of emacs and emacsclient.

When my system emacsclient is used instead of my custom build emacs, I'm getting a similar error:

$ /usr/bin/emacsclient --version
emacsclient 22.1

$ /usr/bin/emacsclient .
/usr/bin/emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

With the correct version:

$ /usr/local/bin/emacsclient --version
emacsclient 26.0.50

$ /usr/local/bin/emacsclient .
Waiting for Emacs...
| improve this answer | |
  • This solves my problem – xtt Dec 10 '17 at 15:24

For unfathomable reasons, this just happened to me on a FC28 upgrade of my laptop. Even stracing ddid not help. After perusing several links (this included), I came up by sticking these lines:

# bash syntax
# On laptop, emacscclient cannot find emacs socket any longer (after FC28)
export EMACS_SERVER_SOCKET=${TMPDIR:-/tmp}/emacs$(id -u)/server
alias emacsclient="/usr/bin/emacsclient -s $EMACS_SERVER_SOCKET"

Which does not hardcode the '1000' part (which just happpens to be the id of the first user created on this particular machine, duh), and accounts for TMPDIR. Exporting EMACS_SERVER_SOCKET is cute, but useless, as emacsclient does not allow that to be configured from an env var (unreasonably, IMHO).

If full control is preferred, one can put:

(setq server-socket-dir "~/.emacs.d/server-dir") 

somewhere before server-start in their .emacs, and use "~/.emacs.d/server-dir/server" as the server socket name for the above mentioned alias. server-dir will be automatically created, with the right permissions 0700, if it does not already exist.

| improve this answer | |

Not necessarily the answer you are looking for, but I have in exactly the same setup always used just emacsclient -c or emacsclient -t. Meaning I don't start the server manually, the first invoking of either will start the server and any subsequent invoking will connect to the server.

| improve this answer | |
  • This works for me, but again, within each specific terminal. So, if I start a new terminal, it will start a new server. – Matías Guzmán Naranjo Sep 17 '17 at 14:20
  • Do you have any server specific stuff in your .emacs? If so, I'd comment it out and try again. Otherwise I am out of ideas. – gaussian Sep 17 '17 at 14:24
  • Also: which version of Emacs you are running? My setup works with both Emacs25 (25.1) from the Ubuntu depo and self-compiled Emacs25.2. – gaussian Sep 17 '17 at 14:40
  • I don't think I have anything in the init file. I am running 25.3, but the same happened with 25.2. Also, launching the server with emacs -q --daemon does the same thing. – Matías Guzmán Naranjo Sep 17 '17 at 14:43
  • Out of ideas, sorry. Works in my setup, even with emacs -q --daemon. – gaussian Sep 17 '17 at 14:49

Create a script say "myemacs" as below:

emacsclient -a '' -c "$@"

Run it will create daemon if not exist, and will connect to daemon if daemon exist.

| improve this answer | |
  • This does not work. I get the same problem, If I launch it from two different terminals it creates a new daemon each time. – Matías Guzmán Naranjo Sep 19 '17 at 15:38
  • @MatíasGuzmánNaranjo Oh, but I saw you are using "-t", I am using "-c". Did you try "-c" also? – lucky1928 Sep 19 '17 at 18:56
  • that doesn't change anything, it's the same behavior with either -c or -t. The client just can't find the server. – Matías Guzmán Naranjo Sep 19 '17 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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