2

I am using Emacs 24 in an work environment where I cannot modify what are outside of my personal folder.

I want to install a particular package, but there is already an older version of this package installed outside of my personal folder. I have to install it manually, so I added the package folder path to 'load-path' and required it myself in init.el file. But still, after the startup, when I check the version, it showed that the version is still the older version which is loaded from a place outside of my personal folder.

My question is how can I mask that older package? In another word, how can I choose to load my version instead?

lebesgue
  • 837
  • 4
  • 13

1 Answers1

2

The key is to modify the the load-path variable at the very beginning of your init.el file.

add-to-list adds to the front of a list. For example, this is how I load my version of org:

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

I also suggest that you inspect the contents of the variable (use Meta-x describe-variable). This will inform you what directories are scanned first.

Be warned, sometimes mixing packages creates weird issues. If this happens, be patient and try one package at a time.

Addendum: as Drew mentioned below, emacs will try to find a package to load in each of the directories in the load-path, starting from its head. So the order of the directories in it matter.

--dmg

dmg
  • 4,231
  • 1
  • 18
  • 24
  • The order of the entries in `load-path` matters. If the other directory where the package is located is listed before yours then it will be used, not yours. But if the library is already preloaded before your init file is loaded then you'll have to explicitly load the library, using `load-library` instead of `require` (after updating `load-path` as shown in this answer). – Drew May 31 '18 at 00:07
  • @Drew Thanks for the comments. I think this is what happens to me now. Because when I check the package version, it still gives me the older version. So, for load-library, I can just give the same argument as require? For example, change from (require 'org) to (load-library 'org)? – lebesgue May 31 '18 at 14:46
  • @dmg Thanks! But when I check the package version, it still gives me the older version number. So, is it the case that the package is preloaded? If so, what do you suggest? – lebesgue May 31 '18 at 14:47
  • @Drew I just tried load-library, but still checking the version just gives me the older version. Any suggestions or ideas? – lebesgue May 31 '18 at 14:59
  • 1
    mm, i have a suggestion. erase your .emacs.d/init.el, so nothing is loaded by you. then run emacs. Check if the package is loaded, and its version. In that case, it means that the system configuration is preloading that package before yours. In that case you need to modify the system-wide init file. – dmg May 31 '18 at 21:49
  • If `M-x load-library` does not load the right version then it is because your own directory does not precede the other-version's directory, in your `load-path`. Unlike `require`, function `load-library` loads the library unconditionally, even if it (any version) has already been loaded. It's apparently loading the library, but the wrong version. Check what `C-h v load-path` tells you. – Drew May 31 '18 at 23:55
  • @Drew Yes, I checked the load-path, and my path (contains the newer version) is ahead of the system one (contains the older version). But, when I check the version, I still got the old version information and its associated load location, which is not what I specified. – lebesgue Jun 01 '18 at 18:27
  • @Drew Also, the library I want to install contains a lot of .el files as dependencies and one main .el file which is specified as the argument for load-library function. So, is it possible that the main file is correctly loaded from my path but all its dependencies are still loaded from the older version path? – lebesgue Jun 01 '18 at 18:29
  • I can't speak for any particular library. But normally a library automatically loads its dependencies when it is loaded - or at least it establishes autoloading for them. – Drew Jun 01 '18 at 19:58
  • Anyway, start by starting Emacs using `emacs -Q` (no init file) and then trying to load the library using `M-x load-library` (after putting its location in your `load-path`, using `M-: (add-to-list 'load-path "/the/path/to/its/directory")`. In other words, take your init file out of the problem. – Drew Jun 01 '18 at 20:00
  • @Drew I did this procedure. The load is successful but the problem is that when I check the version, I still got the older version instead of what I am loading. – lebesgue Jun 04 '18 at 13:32
  • So it sounds like it is loading, but loading the wrong version. Show your `load-path`. Sounds like the directory you want it to load from is farther down the `load-path` than is the directory it is actually loading from. – Drew Jun 04 '18 at 13:53
  • @Drew Actually it is not the case. After I call load-path, the path which I want to load from is actually ranked the 1st, and the load-library process states that the file is loaded from the correct path (the path contains the newer version). However, the version I got is still the old version. – lebesgue Jun 04 '18 at 15:07
  • I think you'd have to show some code, in that case, for people to be able to help. In any case, StackOverflow is not especially the place for interactive debugging. Perhaps try help-gnu-emacs@gnu.org, providing more concrete info - a step-by-step recipe that starts from `emacs -Q`. – Drew Jun 04 '18 at 16:44