go: cannot find GOROOT directory error on installing go in wsl

I've installed go v1.14.2 in my root, gave it permission and then moved the go folder to another drive

/mnt/d/go

Now in the .profile and .bashrc file I've already exported the GOROOT as well as GOPATH and it looks like this.

export GOROOT=$mnt/d/go
export GOPATH=$mnt/d/go_space
export PATH=$PATH:/mnt/d/go/bin:$GOPATH/bin

On running go version, I'm getting

go: cannot find GOROOT directory: /d/go
2

1 Answer

It should be:

export GOROOT=/mnt/d/go
export GOPATH=/mnt/d/go_space
export PATH=$PATH:/mnt/d/go/bin:$GOPATH/bin

Because mnt is not set as anything, $mnt will return nothing.

Log out and log back in to apply the changes.


You see, PATH is an environment variable which is already set. You can run the following command to show what it is set to:

echo $PATH

There are also other variables, like HOME and USER too:

echo $HOME
echo $USER

and you can set your own:

export foo=bar

and check it:

echo $foo

and you can also add something like hello to foo like this:

export foo=hello:$foo
echo $foo

or

export foo=$foo:hello
echo $foo
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like