SOLVED

How to introduce Java commands into PowerShell on Linux platform.

%3CLINGO-SUB%20id%3D%22lingo-sub-3275509%22%20slang%3D%22zh-CN%22%3EHow%20to%20introduce%20Java%20commands%20into%20PowerShell%20on%20Linux%20platform.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3275509%22%20slang%3D%22zh-CN%22%3E%3CP%3EAs%20shown%20in%20the%20following%20figure%2C%20I%20can't%20use%20Java%20commands%20in%20PowerShell%20on%20Linux%20platform.%20How%20to%20set%20PowerShell%20to%20use%20Java%20commands%20on%20Linux%20platform.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22QQ%E6%88%AA%E5%9B%BE20220404235337.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F361159iF35DED80011B01F7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22QQ%E6%88%AA%E5%9B%BE20220404235337.png%22%20alt%3D%22QQ%20screenshot%2020220404235337%20.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3275509%22%20slang%3D%22zh-CN%22%3E%3CLINGO-LABEL%3EJava%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%20for%20Linux%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3275654%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20introduce%20Java%20commands%20into%20PowerShell%20on%20Linux%20platform.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3275654%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1352744%22%20target%3D%22_blank%22%3E%40fsq2018%3C%2FA%3E%26nbsp%3BThe%20Java%20program%20is%20perhaps%20not%20in%20your%20path%3F%20If%20you%20do%20a%20write-host%20%24env%3APATH%2C%20what%20does%20it%20show%20you%3F%20If%20the%20path%20in%20which%20Java%20is%20located%20is%20missing%2C%20then%20you%20can%20add%20it%20to%20your%20Powershell%20profile%20by%20running%20nano%20%24profile%20and%20adding%20and%20restart%20PowerShell%20to%20load%20the%20adjusted%20profile%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24env%3APath%20%2B%3D%20%22%2Fpath%2Fto%2Fjava%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20the%20path%20should%20be%20in%20your%26nbsp%3B%3CSPAN%3E~%2F.bash_profile%20as%20JAVA_HOME%3F%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

As shown in the following figure, I can't use Java commands in PowerShell on Linux platform. How to set PowerShell to use Java commands on Linux platform.

QQ截图20220404235337.png

3 Replies
best response confirmed by fsq2018 (Occasional Contributor)
Solution

@fsq2018 The Java program is perhaps not in your path? If you do a write-host $env:PATH, what does it show you? If the path in which Java is located is missing, then you can add it to your Powershell profile by running nano $profile and adding and restart PowerShell to load the adjusted profile:

 

$env:Path += "/path/to/java"

 

I think the path should be in your ~/.bash_profile as JAVA_HOME? 

@Harm_Veenstra 

Thank you for your reply. I tried $env: path and found that there was no Java path,
while in my ~/.bash_profile file, there is a Java path
fsq2018_0-1649134229986.png

 

Then I modified the powershell profile file

 

 

$env:path+="/home/fang/.jdk/bin" ​

 

 

fsq2018_1-1649134229988.png

 

then I finally found that it work out.
 
fsq2018_2-1649134229989.png

 

 
In Windows it automatically takes the path settings into the powershell session, in Linux it's different so it seems. Good to hear that this works