g icon indicating copy to clipboard operation
g copied to clipboard

安装后,使用go -version报错

Open donghao8455 opened this issue 3 years ago • 2 comments

PS C:\Users\donghao\Desktop> g uninstall 1.18.9 Uninstalled go1.18.9

PS C:\Users\donghao\Desktop> g install 1.18.9 Computing checksum with SHA256 Checksums matched Now using go1.18.9

PS C:\Users\donghao\Desktop> go -version go: The term 'go' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

应该是软连接 没有创建成功,但是不知道哪里配置错误了,起码安装过程中没有报错,望指教

donghao8455 avatar Jan 07 '23 14:01 donghao8455

使用的是哪个版本的Windows系统?Windows系统下创建软连接会优先调用mklink这个外部命令。我身边没有Windows设备,无法去验证,你手动调用 mklink 试着创建下软连接,一起排查下。

func mkSymlink(oldname, newname string) (err error) {
	if runtime.GOOS == "windows" {
		// Windows 10下无特权用户无法创建符号链接,优先调用mklink /j创建'目录联接'
		if err = exec.Command("cmd", "/c", "mklink", "/j", newname, oldname).Run(); err == nil {
			return nil
		}
	}
	return os.Symlink(oldname, newname)
}

voidint avatar Jan 08 '23 02:01 voidint

碰到类似问题 已解决,可以先看看g.exe所在目录有没有go文件夹的快捷方式图标,如果没有就看看你登录用户(一般是C:\Users\你本地的用户名\.g)有没有go目录,有的话设置GOROOT=C:\Users\你本地的用户名\.g\go

imjohnny avatar Mar 27 '24 05:03 imjohnny