Variables de entorno para JAVA

Soy nuevo en esta distribución de Linux. He estado intentando configurar las variables de entorno que solicita VS Code para poder ejecutar código allí pero me ha sido imposible, bien porque no me deja descargar las cosas de donde pide o bien porque dicen “configura en cierto lado” y no encuentro eso que dicen. Lo que me parece curioso es que, al descargar Eclipse sí pude ejecutar código sin ningún problema.

Mi pregunta es, simple y sencillamente, ¿cómo puedo configurar las cosas para poder compilar y ejecutar código java en mi computador?

Gracias de antemano.

You can install a prebuilt OpenJDK Binary distribution with the following commands:

mkdir ~/jdk15
mkdir ~/Downloads
wget -O ~/Downloads/jdk15.tgz "https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.2%2B7/OpenJDK15U-jdk_x64_linux_hotspot_15.0.2_7.tar.gz"
gzip -dc ~/Downloads/jdk15.tgz | tar --strip-components=1 -xvf - -C ~/jdk15
cat << EOF >> ~/.profile
#JDK
export JDK_HOME=${HOME}/jdk15
export JAVA_HOME=\${JDK_HOME}
export PATH=\${PATH}:\${JDK_HOME}/bin
EOF

Just copy and past them into your Terminal, reboot and you’re fine:
image

-When i try to run it throw an error :frowning: Something how “The file or directory does not exist” :frowning:

Have you just copy-pasted it from the above post into the Terminal? I just tried it on my Test machines and everything worked. Can you please post a Screenshot when the error is thrown.

Sure. I tried step by step and “all in one line”. The pic of the former is:


and the latter is basically the same (i can’t put it because i’m a new user)
Idk if i’m doing somethign wrong or what…

Thank you very much in advance for the help you are giving me

Interesting, for some reason the Downloads directory does not exist in your Home Directory. I’ve updated the script above so that this Directory will be created if it’s not here. Just run it again (copy/paste)

I don’t know what do you do but it works. Thank you so much. Efectively, this download a lot of things and now i can run code in VSCode.

I would like to ask you, what does this script really do and how can I, in the future if it is the case, know what to do. It is good to ask for help but it is also good to know how to do it yourself and, if there were not someone like you, possibly I would be blocked :c
<3

Create two directories in your Home directory:

mkdir ~/jdk15
mkdir ~/Downloads

Download the latest OpenJDK build and put it to a predetermined location and name for further use:

wget -O ~/Downloads/jdk15.tgz "https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.2%2B7/OpenJDK15U-jdk_x64_linux_hotspot_15.0.2_7.tar.gz"

The file is a gzipped-tarball (.tgz), so it’s a uncompressed archive of files which has been compressed after creation. We first uncompress it and pipe the uncompressed output to the tar-Command for further extraction of the contained files to a given directory:

gzip -dc ~/Downloads/jdk15.tgz | tar --strip-components=1 -xvf - -C ~/jdk15

Now, here’s a interesting one. Essentially we want to append some lines of text to another file (.profile in your Home directory to set some variables). The cat-Command outputs either a file given or text piped to it. With the <<-Operator (here-document Operator) we can pipe multiple Lines of text to it until a Delimeter is specified (EOF). The >>-Operator appends the output of a command to the given file.

cat << EOF >> ~/.profile
#JDK
export JDK_HOME=${HOME}/jdk15
export JAVA_HOME=\${JDK_HOME}
export PATH=\${PATH}:\${JDK_HOME}/bin
EOF

The variables JDK_HOME and JAVA_HOME are used by the JDK and the Java Runtime to determine it’s location. The PATH Variable is used by the Shells to know where to look for entered commands. We appended the OpenJDK Path to it.

Wow… It’s no trivial. I thought it would be something more … easier to find. But this is not something found in any forum xd

I saw a comment from you on someone’s post who had a problem with Windows. It’s a bad thing on my part but honestly I see myself very limited being in this system, especially because of the games. Do you think you could give me a hand? It is something that I have not seen anyone else … tr I also appreciate all the trouble you took here

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.