Mac IntelliJ - Cannot run program “docker”: error=2, No such file or directory
fix PATH environment variable for IntelliJ IDEA on Mac OS X
what is the problem?
Recently I wrote a Gradle plugin which uses the docker client of the local machine. When running Gradle from the terminal everything is fine. However, when I import the project into my IntelliJ IDEA and try to run the Gradle tasks using IntelliJ IDEA I keep getting the following error:
Cannot run program “docker”: error=2, No such file or directory
It seems, I am not the only one having this problem:
why the problem exists?
The cause of the problem is a different set of environment variables for terminal and GUI applications in Mac OS X. As the docker client is usually installed via
brew install docker
, the binary is located in /usr/local/bin
. However, the PATH
environment for GUI applications is limited to /usr/bin:/bin:/usr/sbin:/sbin
by default. That means, the docker
command is not available to IntelliJ IDEA. how to solve the problem?
The easiest way is to start IntelliJ IDEA from the terminal:
open -a "IntelliJ IDEA 15"
That way, IntelliJ IDEA uses the same environment variables as declared in your terminal.
However, if you still want to start IntelliJ IDEA using Spotlight, Dock etc., you have to do a bit more.
Another way is to change the
PATH
variable for GUI applications using the following terminal command: sudo launchctl config user path $PATH
This will set the
PATH
variable to the value of your terminal. However, you have to restart your Mac and this change will affect all of your GUI applications. The last way is to edit the application package of IntelliJ IDEA. To spare you from messing around with the package, I wrote a small script that does all the editing for you:
As you can see, the script accepts two input parameters: the absolute path to the IntelliJ IDEA application package (e.g.
/Applications/IntelliJ IDEA 15.app
) and the value of the PATH
variable to set. To apply the changes, download the script, make it executable and run it as follows:
curl https://gist.githubusercontent.com/depressiveRobot/9cb8f799c970f0cd57ea/raw/964253533dd46e0202c4873468b3a1ef304b0af1/osx-intellij-set-path.sh > osx-intellij-set-path.sh
chmod +x osx-intellij-set-path.sh
./osx-intellij-set-path.sh "/Applications/IntelliJ IDEA 15.app" "$PATH"
This will set the
PATH
variable for IntelliJ IDEA to the value of your terminal. With a few minor adjustments this should be portable to the other Jetbrains editors, too, such as WebStorm and even Android Studio. Whichever way you choose, now you’re able to run external commands with IntelliJ. Just like as you know it from the terminal ;)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Rails Turbolinks를 페이지 단위로 비활성화하는 방법원래 Turobolinks란? Turbolinks는 링크를 생성하는 요소인 a 요소의 클릭을 후크로 하고, 이동한 페이지를 Ajax에서 가져옵니다. 그 후, 취득 페이지의 데이터가 천이 전의 페이지와 동일한 것이 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.