javac does not work in ubuntu terminal

后端 未结 6 1067
后悔当初
后悔当初 2021-02-06 23:41

When I try to compile a java program with javac, I get an error:

The program \'javac\' can be found in the following packages:
 * default-jdk
 * ecj         


        
6条回答
  •  花落未央
    2021-02-07 00:19

    In my case, I had the JDK installed, but I'd installed it manually so it wasn't added to the path. Once I added these lines to my .zshrc file (I'm using zsh; if you're using bash, add them to .bash_profile) and relaunched the terminal, it worked:

    # Java environment variables
    export JAVA_HOME='/opt/jdk/jdk1.8.0_241'  #change accordingly; this needs to match your JDK's location!
    export PATH=$PATH:$JAVA_HOME/bin
    

提交回复
热议问题