Vscode-ssh远程开发PATH环境变量不能自动刷新的bug

目录

目录

在使用vscode远程连到Ubuntu上开发golang时偶然遇到了一个奇怪的问题, vscode提示找不到go的二进制文件, 然后列出了环境变量, go相关的环境变量不再里面

1
2
3
Failed to run "go env" to find GOPATH as the "go" binary cannot be found in either GOROOT or PATH...
.....
/home/lomot/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/home/lomot/.zinit/polaris/sbin:/home/lomot/.zinit/polaris/bin:/home/lomot/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/nodejs/bin

但是使用内置终端输出一下环境变量却是有的

1
2
dev2 ~ ᐅ echo $PATH
/home/lomot/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/home/lomot/.zinit/polaris/sbin:/home/lomot/.zinit/polaris/bin:/home/lomot/.vscode-server/bin/c3f126316369cd610563c75b1b1725e0679adfb3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/nodejs/bin:/opt/go/bin:/home/lomot/go/bin:/opt/nodejs/bin:/opt/go/bin:/home/lomot/go/bin

于是去网上查了一下, 好像跟关于.zshrc没有被加载有关, 但是奇怪的是我的.zshrc里面的部分环境变量是已近加载了的, 比如我的/opt/nodejs/bin是通过.zshrc加载的. 对比报错中的环境变量和vscode内置终端中输出的环境变量, 发现少了后面go相关的部分, 而且/opt/nodejs/bin还被加载了两遍.

结论是远程vscode-server只会使用它启动时候的环境变量, 如果需要刷新环境变量需要重启vscode-server,

可以在本地vscode上ctrl+shift+p, 执行Remote-SSH: Kill VS Code Server..

或者连上linux服务器执行

1
ps -aux | grep code

查看vscode服务端的进程然后杀掉, 再重新使用vscode远程连进来. 我在安装go之前就使用过vscode远程服务器, 断开连接后服务器上的code进程并不会退出, 这就导致了我修改的环境变量没有生效. 结果就是我杀掉了服务器上的code后问他就解决了.

参考

https://github.com/microsoft/vscode-remote-release/issues/1671 https://github.com/microsoft/vscode-remote-release/issues/83