Setting environment variables for Sublime Text on

2019-06-19 02:43发布

I'd like to be able to access my JAVA_HOME variable that has been set in my .bash_profile from within my sublime text build. When I build I get the following error.

Error: JAVA_HOME is not defined correctly. We cannot execute ....

This is obviously because ST2 doesn't read in my bash profile. Is there any hack around for this?

Thanks!

1条回答
相关推荐>>
2楼-- · 2019-06-19 03:39

On UNIX child processes inherit the environment of the parent process. In this case, Sublime Text is not launched through a process chain which would include bash shell which in turn is reading its profile file.

.bash_profile is usually executed on shell login. Depending on your operating system it is not executed when you enter to your desktop environment. Thus, the environment variables are not avaiable.

Workarounds

  • Put environment variables to a file which is read on the computer boot always (no idea which file unless you tell your operating system) (e.g. lanchd.conf for OSX GUI applications or /etc/profile on Linux)

  • Modify your dekstop launcher icon

  • Put hardcoded paths to your build file

  • Launch Sublime Text using subl alias from your bash shell instead of desktop icon

More about .bash_profile and .bashrc

查看更多
登录 后发表回答