简体   繁体   English

我可以删除从 Source 构建 NodeJS 时安装的构建依赖项(例如 g++、gcc、libstdc++6 等)吗?

[英]Can I remove the build dependencies installed when building NodeJS from Source (such as g++, gcc, libstdc++6, etc )?

I built NodeJS from source on an ubuntu-slim image.我在 ubuntu-slim 图像上从源代码构建了 NodeJS。 When you do this it requires a lot of package installs in the process, such as (for example. below is Node16 dependencies)当你这样做时,它需要在过程中安装大量 package,例如(例如。下面是 Node16 依赖项)

&& apt-get install --yes \
    libstdc++6 \
... 
...
    && apt-get install --yes \
        binutils-gold \
        g++ \
        gcc \
        gnupg \
        libgcc-7-dev \
        linux-headers-generic \
        make \
        python3 \

Once I have completed installing everything and configuring it, can I simply remove these build dependencies?完成所有内容的安装和配置后,我可以简单地删除这些构建依赖项吗? The image has grown extensively and I need to try to clean as much fat as possible.图像已经广泛增长,我需要尝试尽可能多地清洁脂肪。 Of course, I still want NodeJS to run my node apps.当然,我仍然希望 NodeJS 运行我的节点应用程序。

The same kind of process happens for NodeJS 14, and I am guessing NodeJS 18.. Can we remove these build dependencies once the NodeJS is built? NodeJS 14 也发生了同样的过程,我猜 NodeJS 18 .. 一旦构建了 NodeJS,我们可以删除这些构建依赖项吗?

After completing my building of Node14, I have found that:完成 Node14 的构建后,我发现:

  1. Yes, you can remove the build dependencies after node is completely installed .是的,您可以在 node 完全安装后删除构建依赖项 I proved this specifically on Ubuntu20 OS platform with installing Node14.我通过安装 Node14 在 Ubuntu20 操作系统平台上专门证明了这一点。 The one caveat on this is that you are using Node without needing to install native packages (native node packages require binary compilation against the OS when the package is npm install ed- for example node-sass) - these are not common, so most uses of Node do not require this.对此的一个警告是,您使用 Node 而无需安装本机软件包(当 package 为npm install时,本机节点软件包需要针对操作系统进行二进制编译 - 例如 node-sass) - 这些并不常见,所以大多数使用Node 不需要这个。
  2. How to remove packages .如何删除包 I have found that uninstalling the apk-get packages that were installed is as simple as using apk-get purge .我发现卸载已安装的apk-get软件包就像使用apk-get purge一样简单。 The example below (building node inside a Dockerfile using shell script) gives some specifics.下面的示例(使用 shell 脚本在 Dockerfile 内构建节点)给出了一些细节。
    echo "Building from source" \
    && NODE_BUILD_PACKAGES="binutils-gold g++ gcc libgcc-7-dev linux-headers-generic make python3" \
    && apt-get install --yes ${NODE_BUILD_PACKAGES} \
...
...
[code to build node]
...
    && apt-get purge --yes ${NODE_BUILD_PACKAGES} \
    && apt-get clean \
    && apt-get autoremove --yes \

I used those three commands to clear out the build machine after building Node from source.在从源代码构建 Node 后,我使用这三个命令来清除构建机器。 For clarity, here is what each of those commands does:为清楚起见,以下是每个命令的作用:

  • The command apt-get purge removes the packages that I installed so that I could build Node.命令apt-get purge删除了我安装的包,以便我可以构建 Node.js。
  • The command apt-get clean clears the local repository of retrieved package files that are left in /var/cache.命令apt-get clean清除保留在 /var/cache 中的检索到的 package 文件的本地存储库。
  • The command apt-get autoremove removes packages that were automatically installed because some other package required them.命令apt-get autoremove删除自动安装的软件包,因为其他一些 package 需要它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM