I ran into a problem where I couldn't run some Unix Command in Emacs. I found a package just for this problem so I will share it in this post.
The problem I had
Some of the shell commands weren't working in Emacs, even though they worked in the terminal. The cause of this was that the shell environment in Emacs wasn't the same as in the terminal.
My encounter with the problem
I ran into this problem when I was trying to create diagrams with PlantUML. When I tried to evaluate the PlantUML code, I got the following error.
The operation couldn't be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java.
I was sure that I was able to run Java in my system, so I tried it on my terminal to see if it works.
$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
It was working, so now I tried it in Emacs.
Shell command: java -version
The operation couldn't be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
After some Googling, I found out that when using the GUI version of Emacs, the shell environment in the terminal doesn't get applied on Emacs.
How to resolve the problem
Add the package exec-path-from-shell to your Emacs! The README of the package is very nicely documented. It explains what is happening, and how to set it up in a certain use case. Major thanks to the author!