#vscode# #SSH远程# #Ubuntu 16.04# 远程ubuntu旧版Linux
背景:
Remote Development FAQ
最新的vscode需要glibc 2.28+支持,但是ubuntu16可能不支持(glibc 2.28+),因此无法直接连接报错连接失败!
自Visual Studio Code 1.99起,VSCode Remote - SSH Server由于运行库依赖更新,会无法连接到旧版Linux发行版上。但是好在官方在文档中还给了临时解决办法。这里我搬运一下,其中遇到了一些问题参考了Ssh Remote have problem in old server
方案 1 - 安装历史版本:
下载合适的版本,不建议下载最新的,最新的vscode不支持(glibc 2.28+)
下载地址:
历史下载地址:https://code.visualstudio.com/updates/ 链接进入显示如下:
下载最后一个支持ubuntu1604 的版本 1.85 系列或者之前的都可以。但是有可能不支持最新的插件
November 2023 (version 1.85)
将程序解压出来,在应用程序中新建一个文件夹,将解压后的程序放入其中。为了与另一个版本区分,我把app名字改成了Visual Studio Code_1.85.2。
在app的同级文件夹下创建code-portable-data文件夹,运行如下命令,将app移除quarantine属性。
cd app所在路径
xattr -dr com.apple.quarantine XXX.app
现在你就可以打开这个程序,不会与原有 vscode 冲突了
打开后,需要把自动更新的设置取消。
方案 2 - 更新服务器部分库:
编译安装crosstool-NG
sudo apt-get install -y texinfo
sudo apt-get install -y libtool
sudo apt install libtool-bin
sudo apt-get install -y bison
sudo apt-get install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip patch rsync meson ninja-build
mkdir remote_ssh_ubuntu_1604
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.26.0.tar.bz2
tar -xjf crosstool-ng-1.26.0.tar.bz2 && cd crosstool-ng-1.26.0
./configure && make && sudo make install
用crosstool-NG编译新版sysroot,其中包含所需的新版运行库
mkdir toolchain-dir && cd toolchain-dir
wget https://github.com/microsoft/vscode-linux-build-agent/raw/refs/heads/main/x86_64-gcc-8.5.0-glibc-2.28.config
mv x86_64-gcc-8.5.0-glibc-2.28.config .config
ct-ng menuconfig
# 在menuconfig图形菜单中,将“Operating System”选项下的“Version of linux”改为不高于你系统的Linux内核版本。你的版本可以通过uname -a命令查看,比如我这里就改为了4.14.319。选择好以后在底部菜单先Save再Exit。
ct-ng build
# 这个过程需要下载编译一堆东西,耐心等待二十分钟
下载安装,测试patchelf
wget https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-x86_64.tar.gz
sudo tar -zxf patchelf-0.18.0-x86_64.tar.gz -C /
gcc hello_world.c
./a.out
patchelf --set-interpreter /path/to/toolchain-dir/x86_64-linux-gnu/x86_64-linux-gnu/sysroot/lib/ld-linux-x86-64.so.2 --set-rpath /path/to/toolchain-dir/x86_64-linux-gnu/x86_64-linux-gnu/sysroot/lib64 a.out
./a.out
ldd a.out
设置环境变量
export VSCODE_SERVER_CUSTOM_GLIBC_LINKER=/path/to/toolchain-dir/x86_64-linux-gnu/x86_64-linux-gnu/sysroot/lib/ld-linux-x86-64.so.2
export VSCODE_SERVER_CUSTOM_GLIBC_PATH=/path/to/toolchain-dir/x86_64-linux-gnu/x86_64-linux-gnu/sysroot/lib64
export VSCODE_SERVER_PATCHELF_PATH=/bin/patchelf
将上述内容放到你~/.bashrc文件的开头!一定是开头!
现在可以在VSCode上通过SSH尝试连接到ubuntu_1604