1

If use iTerm on macOS, we can set env values in its terminal. It also set path such as /usr/local/bin/ in ~/.bashrc.

But in emacs' terminal as eshell, run kubectl shown kubectl: No such file or directory. It seems that it didn't find the command's path.

How to set path for emacs? For example, in spacemacs.

I found this exec-path-from-shell

M-x package-install exec-path-from-shell RET

Edit ~/.emacs.d/init.el to add

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

to the bottom.

Copy PATH from .bashrc to .profile.

$ cat ~/.profile
export PATH=/usr/local/bin:/usr/bin:/bin

Start GNU Emacs For Max OS X still can't find the command's path in eshell. The spacemacs alert:

Warning (initialization): An error occurred while loading ‘/Users/user/.emacs.d/init.el’:

Symbol's function definition is void: exec-path-from-shell-initialize

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

The full file of ~/.emacs.d/init.el:

;;; init.el --- Spacemacs Initialization File -*- no-byte-compile: t -*-
;;
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

;; Without this comment emacs25 adds (package-initialize) here
;; (package-initialize)

;; Avoid garbage collection during startup.
;; see `SPC h . dotspacemacs-gc-cons' for more info
(defconst emacs-start-time (current-time))
(setq gc-cons-threshold 402653184 gc-cons-percentage 0.6)
(load (concat (file-name-directory load-file-name)
              "core/core-versions.el")
      nil (not init-file-debug))
(load (concat (file-name-directory load-file-name)
              "core/core-load-paths.el")
      nil (not init-file-debug))
(load (concat spacemacs-core-directory "core-dumper.el")
      nil (not init-file-debug))

;; Clean compiled files if they become stale or Emacs version has changed.
(load (concat spacemacs-core-directory "core-compilation.el")
      nil (not init-file-debug))
(load spacemacs--last-emacs-version-file t (not init-file-debug))
(let ((default-directory spacemacs-start-directory))
  (when (or (not (string= spacemacs--last-emacs-version emacs-version))
            (spacemacs//contains-newer-than-byte-compiled-p
             spacemacs--compiled-files))
    (spacemacs//remove-byte-compiled-files spacemacs--compiled-files)))
(when (not (string= spacemacs--last-emacs-version emacs-version))
  (spacemacs//update-last-emacs-version))

(if (not (version<= spacemacs-emacs-min-version emacs-version))
    (error (concat "Your version of Emacs (%s) is too old. "
                   "Spacemacs requires Emacs version %s or above.")
           emacs-version spacemacs-emacs-min-version)
  ;; Disable file-name-handlers for a speed boost during init
  (let ((file-name-handler-alist nil))
    (require 'core-spacemacs)
    (spacemacs/dump-restore-load-path)
    (configuration-layer/load-lock-file)
    (spacemacs/init)
    (configuration-layer/stable-elpa-init)
    (configuration-layer/load)
    (spacemacs-buffer/display-startup-note)
    (spacemacs/setup-startup-hook)
    (spacemacs/dump-eval-delayed-functions)
    (when (and dotspacemacs-enable-server (not (spacemacs-is-dumping-p)))
      (require 'server)
      (when dotspacemacs-server-socket-dir
        (setq server-socket-dir dotspacemacs-server-socket-dir))
      (unless (server-running-p)
        (message "Starting a server...")
        (server-start)))))

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))
New contributor
oiio is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

The init file ~/.emacs.d/init.el seems to be at the wrong place. It's better be at the home folder which is ~/

Besides, the code to inject the PATH contents into emacs seems wrong. So, comment them out and try adding the following into the ~/.emacs which is the most conventional init file for emacs and change ~/.bash_profile to whatever you use as the bash init file (in your case it seems to be /.bashrc) and then of course restart the emacs.

(let ((path (shell-command-to-string ". ~/.bash_profile; echo -n $PATH")))
  ;;  the dot . makes it execute the ~/bash_profile
  ;; echo -n $PATH prints out the PATH contents
  (setenv "PATH" path)
  (setq exec-path 
    (append
     (split-string-and-unquote path ":")
     exec-path)))

Furthermore, first try it with the M-x shell not the eshell because eshell is an extra feature not essential.

2
  • Can you give us a link to a source in support of the proposition that the init.el must be in the home folder? In addition, how does your answer resolve the error message reported by the O.P.?: "Symbol's function definition is void: exec-path-from-shell-initialize" – lawlist Feb 23 at 16:09
  • .emacs being in the home folder is not a must but a usual preference (edited the post) The answer apparently doesn't resolve the error message, it just solves setting the env values for the shell (no guarantees for the eshell) – Terry Feb 23 at 17:13

Your Answer

oiio is a new contributor. Be nice, and check out our Code of Conduct.

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.