vscode remote ssh如何搭配goenv切换golang版本
Word Count: 315(words)
Read Count: 1(minutes)
问题大概就是,当我在远程服务器使用goenv安装了多个golang版本的时候,使用vscode的remote ssh方式远程连接服务器,vscode的shell无法自动切换到对应的golang版本。
发现vscode shell里面的环境变量用的是老的,似乎没有加载~/.bash_profile里面的环境变量。于是找到了remote-ssh的这个issue。争论了挺久的,有兴趣可以看完。
解决方法是在settings.json文件里面配置指定要使用login shell:
1 2 3 4 5 6 7 8 9 10 11
| { "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { "path": "bash", "args": [ "-l" ] } } }
|
注意,这个配置只能够解决vscode shell中golang版本没切换的问题,但是vscode golang插件此时用的golang版本可能也是错误的。我们还需要给vscode golang插件配置一下,例如:
1 2
| "go.goroot": "/root/.goenv/versions/1.17.8", "go.gopath": "/root/go/1.17.8"
|
所以,最终的配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { "path": "bash", "args": [ "-l" ] } }, "go.goroot": "/root/.goenv/versions/1.17.8", "go.gopath": "/root/go/1.17.8" }
|