centOS8 踩坑eclipse-theia,在线IDE

作者: TAIS3 分类: JavaScript,杂七杂八 发布时间: 2023-07-05 11:05

偶然的机会要求熟悉一下这款在线的IDE,eclipse-theia,于是踩坑开始!

官网:https://theia-ide.org/
官网文档:https://theia-ide.org/docs

砍柴不误磨刀工,首先要了解一下准备工作:

Prerequisites

  • Node.js >= 16.14.0 and < 17.
    • If you are interested in Theia’s VS Code Extension support then you should use a Node version at least compatible with the one included in the version of Electron used by VS Code.
  • Yarn package manager >= 1.7.0 AND < 2.x.x.
  • git (If you would like to use the Git-extension too, you will need to have git version 2.11.0 or higher.)
  • Python3 is required for the build due to node-gyp@8.4.1

Some additional tools and libraries are needed depending on your platform:

  • Linux

    • make
    • gcc (or another compiling toolchain)
    • pkg-config
    • build-essential: sudo apt-get install build-essential
    • native-keymap native node module dependencies:
      • Debian-based: sudo apt-get install libx11-dev libxkbfile-dev
      • Red Hat-based: sudo yum install libX11-devel.x86_64 libxkbfile-devel.x86_64 # or .i686
      • FreeBSD: sudo pkg install libX11
    • keytar native node module dependencies (reference):
      • Debian/Ubuntu: sudo apt-get install libsecret-1-dev
      • Red Hat-based: sudo yum install libsecret-devel
      • Arch Linux: sudo pacman -S libsecret
      • Alpine: apk add libsecret-dev
  • Linux/MacOS

    • nvm is recommended to easily switch between Node.js versions.
  • Windows

    • We recommend using scoop. The detailed steps are here.

上面摘自官网的,https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites,简单翻译一下:

  • Node.js要求, 16.14.0 以上  17以下
  • yarn包管理器 1.7以上2.0以下
  • git环境
  • python3,另外要求node-gyp@8.4.1

此外,linux另外要求

  • make工具
  • gcc
  • pkg-config
  • native-keymap(重点)
  • keytar(重点)

上面两个重点非常折腾,原文给出了一些解决的参考,但是不靠谱,我们后面会说到!最后建议用nvm作为node的版本管理器

一、安装nvm以及node

1.使用 curl 命令下载并安装 NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

2.重启终端,或者执行以下命令使 NVM 生效:

source ~/.bashrc

3.检查 NVM 是否成功安装:

nvm --version

4.使用 NVM 安装 Node.js,安装指定版本(例如 16.20.1,我们后面使用这个版本的node进行操作):

nvm install 16.20.1

5.安装完成后查看版本

node -v
npm -v

输出node以及npm版本号证明安装成功

二、安装MAKE

使用下面的命令安装make

sudo dnf install make

三、安装gcc

sudo dnf install gcc

安装完成后,可以通过运行以下命令验证 GCC 是否成功安装:

gcc --version

四、安装pkg-config

sudo dnf install pkg-config

安装完成后,您可以通过运行以下命令验证 pkg-config 是否成功安装:

pkg-config --version

五、安装build-essential

在 CentOS 8 上,没有名为 build-essential 的软件包,该软件包主要用于 Debian 和 Ubuntu 等 Debian-based 发行版。在 CentOS 8 中,可以通过安装 Development Tools 软件包来获取类似的功能。以下是在 CentOS 8 上安装 Development Tools 的步骤:

以管理员身份运行以下命令以安装 Development Tools

sudo dnf groupinstall "Development Tools"

安装完成后,您可以通过运行以下命令验证开发工具是否成功安装:

gcc --version
make --version
autoconf --version

六、安装native-keymap

在项目目录中,运行以下命令以安装 native-keymap

npm install native-keymap

这个模块你有可能会碰到各种报错,缺少依赖,一般来说搜到相关的依赖安装上就好了,其中有一个依赖比较麻烦,报错是这样的:

[4/4] Building fresh packages…
[8/10] ⠠ electron
[-/10] ⠠ waiting…
[6/10] ⠠ oniguruma
[9/10] ⠠ native-keymap
error /home/theia/theia-hello-world-extension/node_modules/native-keymap: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /home/theia/theia-hello-world-extension/node_modules/native-keymap
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@6.0.1
gyp info using node@10.18.0 | linux | x64
gyp info find Python using Python version 3.6.8 found at “/usr/bin/python3”
gyp info spawn /usr/bin/python3
gyp info spawn args [ ‘/home/theia/theia-hello-world-extension/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py’,
gyp info spawn args ‘binding.gyp’,
gyp info spawn args ‘-f’,
.
.
.
gyp info spawn args ‘build’,
gyp info spawn args ‘-Goutput_dir=.’ ]
Package x11 was not found in the pkg-config search path.
Perhaps you should add the directory containing `x11.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘x11′ found
Package xkbfile was not found in the pkg-config search path.
Perhaps you should add the directory containing `xkbfile.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘xkbfile’ found
gyp: Call to ‘pkg-config x11 xkbfile –cflags | sed s/-I//g’ returned exit status 0 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/home/theia/theia-hello-world-extension/node_modules/electron-rebuild/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 3.10.0-693.el7.x86_64
gyp ERR! command “/home/theia/.nvm/versions/node/v10.18.0/bin/node” “/home/theia/theia-hello-world-extension/node_modules/.bin/node-gyp” “rebuild”
gyp ERR! cwd /home/theia/theia-hello-world-extension/node_modules/native-keymap

官方给的方法是:

sudo yum install libx11-devel.x86_64 libxkbfile-devel.x86_64 # or .i686

但是我发现没什么用,搜了一轮都没解决方法,最后直接下载libxkbfile-devel-1.1.0-1.el8.x86_64.rpm,离线安装,链接:https://rhel.pkgs.org/8/okey-x86_64/libX11-devel-1.6.7-1.el8.x86_64.rpm.html

七、安装keytar

在项目目录中,运行以下命令以安装 keytar

npm install keytar

安装这个也可能会出现报错,如:

Package libsecret-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsecret-1.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘libsecret-1’ found
gyp: Call to ‘pkg-config –libs-only-l libsecret-1’ returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/www/server/nvm/versions/node/v12.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:223:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 5.4.0-1043-raspi
gyp ERR! command “/www/server/nvm/versions/node/v12.15.0/bin/node” “/www/server/nvm/versions/node/v12.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild”

这个看官方的解决方法,安装依赖即可:

sudo yum install libsecret-devel

上面准备工作处理好后, 可以进行下一步:

Quick Start

To build and run the browser example:

git clone https://github.com/eclipse-theia/theia \
    && cd theia \
    && yarn \
    && yarn download:plugins \
    && yarn browser build \
    && yarn browser start

上面是官方的快速开始,当前theia 的版本最新是1.3.9,在上面命令中,最后一个yarn browser start我们可以换成:

yarn browser start /my-workspace --hostname 0.0.0.0 --port 3000

这样就可以指定打开workspace还有指定监听的端口。

在此期间,可能还会碰到electron 安装报错,可能是网络原因或者是权限的问题,这个搜索一下不难解决。

最后提一下,安装的时候有个报错可能是这样的:

[4/4] Building fresh packages...
[1/9]  XXXXX
[2/9]  XXXXX
[3/9]  XXXXX
[4/9]  XXXXX
error /theiaide/node_modules/XXXXX: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /theiaide/node_modules/XXXXX
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.15.0 | linux | x64
gyp http GET https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: read ECONNRESET
gyp ERR! stack at TLSWrap.onread (net.js:622:25)
gyp ERR! System Linux 3.10.0-862.11.6.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /theiaide/node_modules/XXXXX
gyp ERR! node -v v8.15.0

官方在界面上也特别提到了这个问题,官方给出的解决方法是:

This happens because node-gyp does not rely on system/NPM proxy settings. In that case, download the node-headers file using the link provided in the error stack (in the example above https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz) and run the build with the following command:

npm_config_tarball=/path/to/node-v8.15.0-headers.tar.gz yarn install

其实就是在上面的quick start的命令中,把其中的一条,yarn 换成这个命令,离线安装node-v8.15.0-headers.tar.gz,注意,这个文件的版本跟你nodeJS的版本有关,根据提示下载好相对应的版本安装即可。

发表回复