Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the PATH and other environment variables available in emacs

Working with emacs in OSX can some times be troubling.

I interchange with using the Terminal.app application and the emace shell both of these use bash, and both seem to work, I do however have the problem that the environment is not setup identically in both.

I'm running a clean installation of OSX Lion, and emacs 24 from emacs and would like for the environment variables in the emacs shell to make the same as in the Terminal.app under osx. How do I fix that?

like image 468
Martin Kristiansen Avatar asked May 21 '13 18:05

Martin Kristiansen


People also ask

How do I set environment variables in Emacs?

Inside Emacs, the command M-x getenv reads the name of an environment variable, and prints its value in the echo area. M-x setenv sets a variable in the Emacs environment, and C-u M-x setenv removes a variable.

How do I set path in Emacs?

If all you need this for is Emacs, you can of course just set both exec-path and PATH in your . emacs . You can set PATH using (setenv "PATH" (format "%s:%s" "/new/path/element" (getenv "PATH"))) .

How do I set environment variables in vim?

Vim can read and write environment variables within your current shell session. Use a $ prefix to identify an environment variable, as in the following examples. Insert the contents of the PATH environment variable into the buffer: Press i to enter insert mode, press Ctrl-r then =$PATH and press Enter.


2 Answers

Just install the awesome little package exec-path-from-shell and you're done! It will automatically set your emacs exec-path to be same as the PATH in your zsh/bash config.

It will also allow you to copy the values of other shell variables like this:

(exec-path-from-shell-copy-env "PYTHONPATH")
like image 158
Bozhidar Batsov Avatar answered Sep 22 '22 08:09

Bozhidar Batsov


If your environment variables are being set in ~/.bash_profile, Create a file called ~/.emacs_bash and put in it the following:

. ~/.bash_profile

Don't forget the newline at the end of that line or it won't be executed.

~/.emacs_bash is loaded by emacs when you run bash from within it, such as when using M-x shell or shell-command so you can use it to set any environment variables you want available.

like image 43
Burton Samograd Avatar answered Sep 21 '22 08:09

Burton Samograd