when I do C-h v and look up exec-path, I get the following:


However, when I try to run nvcc from M-x compile, it says "nvcc not found". If I give it the full path /usr/local/cuda/bin/nvcc, it works fine.

I thought having the path in exec-path is supposed to let me use nvcc, why is it not? Also, when I do M-! echo "$PATH", it prints


which is missing the last two elements of exec-path from above. Though I guess that's because exec-path takes precedence, so whatever. But in that case, why isn't the last element of exec-path "taking effect" in my case?

Note that when I go into an ordinary terminal (outside emacs) and do echo "$PATH", I get the following:


though it's less surprising that emacs didn't capture that path which was from .bashrc.

  • 1
    Does this answer your question? exec-path and $PATH
    – mmmmmm
    Commented May 28, 2022 at 11:09
  • no, because that answer tells me to do the thing I've already tried and doesn't work: put the item in exec-path, while I need to set the PATH env variable to actually get it to work
    – xdavidliu
    Commented May 28, 2022 at 11:20
  • The first paragragh of the accepted answer does say "But if you run a command, it will inherit PATH, not exec-path, so subprocesses can find different commands than Emacs does." and comments on the issue
    – mmmmmm
    Commented May 28, 2022 at 11:23

2 Answers 2


I had to do this in order to get nvcc to work from M-x compile.

(setenv "PATH" (concat "/usr/local/cuda/bin:" (getenv "PATH")))

I actually also reverted the changes to exec-path, as those didn't seem to matter one way or the other.


The function 'compile' runs the command you give it in a shell.

The command is found by the shell through function start-file-process-shell-command and so the environment variable $PATH is the one that is used. Thus explaining whey your solution of adding "/usr/local/cuda/bin:" to PATH is needed.

See this answer for more

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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