I have the following ~/.emacs:

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.

(require 'highlight-symbol)
(global-set-key [(control f3)] 'highlight-symbol)
(global-set-key [f3] 'highlight-symbol-next)
(global-set-key [(shift f3)] 'highlight-symbol-prev)
(global-set-key [(meta f3)] 'highlight-symbol-query-replace)

Then I added the file highlight-symbol.el to my ~/.emacs.d folder.

However when I start emacs I get:

Warning (initialization): An error occurred while loading ‘~/.emacs’:

File error: Cannot open load file, No such file or directory, highlight-symbol

I am new to emacs, what am I doing wrong?

2 Answers 2


Looking at the help from require (C-h f require)

(require FEATURE &optional FILENAME NOERROR)

If feature FEATURE is not loaded, load it from FILENAME. If FEATURE is not a member of the list 'features', then the feature is not loaded; so load the file FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, and 'load' will try to load this name appended with the suffix '.elc' or '.el', in that order.

So let's look at load help (either C-h f load or simply use TAB to navigate to the blue link then useRET):

This function searches the directories in `load-path'.

Again we can have a look at load-path help (either C-h v load-path, since it's a variable, or navigating to the link) and, probably, find that .emacs.d is not in the list.

This can be fixed by adding this to the init file:

(add-to-list 'load-path "~/.emacs.d")

For it to take effect immediately you can use C-x C-e (eval-last-sexp) with point at end of line.

  • 1
    Can I just say that your step by step was far more important than the answer? Thank you!! Commented Aug 3, 2023 at 0:48

I'm not sure about the time this question was asked, but today (Emacs 26.3) I've run into the same error. My config was basically like so:

 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (expand-region))))

(require 'expand-region)

The reason it didn't work was because by the time require was executed, ~/.emacs.d/elpa/expand-region-XXXXXXXX.XXXX was not in load-path. I fixed by putting require inside after-init-hook:

(add-hook 'after-init-hook (lambda () (progn
  (require 'expand-region)

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.