#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

相关推荐
chlk12316 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑16 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件17 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
埃博拉酱4 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端