{"id":18934,"date":"2025-08-29T08:33:08","date_gmt":"2025-08-29T00:33:08","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=18934"},"modified":"2026-04-02T10:42:28","modified_gmt":"2026-04-02T02:42:28","slug":"nvm","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2025\/08\/29\/nvm\/","title":{"rendered":"\u901a\u8fc7nvm\u7ba1\u7406\u591a\u7248\u672cnode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u901a\u8fc7jenkins\u6784\u5efa\u524d\u7aef\u9879\u76ee\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u78b0\u5230\u4e0d\u540c\u7684\u524d\u7aef\u9879\u76ee\u4f7f\u7528\u4e0d\u540c\u7684node\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u5207\u6362\u7248\u672c\u6765\u6784\u5efa\uff0c\u5982\u679c\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684node\uff0cnvm\u5c31\u662f\u4e00\u4e2a\u597d\u7528\u7684node\u7248\u672c\u7ba1\u7406\u5de5\u5177<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nvm\u5b89\u88c5\u4e5f\u6709\u5728\u7ebf\u548c\u79bb\u7ebf\u7684\u533a\u522b\uff0c\u5728\u7ebf\u5b89\u88c5\u9700\u8981\u6267\u884c\u811a\u672c\uff0c\u5e76\u9700\u8981\u8bbf\u95eegithub\uff0c\u5f88\u5927\u7a0b\u5ea6\u4f1a\u51fa\u73b0\u7f51\u7edc\u8d85\u65f6\u7684\u60c5\u51b5\uff0c\u5728\u7ebf\u5b89\u88c5\u53ef\u53c2\u8003\u94fe\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;nvm.uihtm.com\/doc\/install.html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u4f8b\u5b50\u6f14\u793a\u4e3a\u79bb\u7ebf\u5b89\u88c5\uff0c\u56e0\u4e3a\u6211\u7684\u670d\u52a1\u5668\u8bbf\u95eegithub\u4e0d\u884c\uff0c\u603b\u662f\u5931\u8d25<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nvm \u672c\u8eab\u53ea\u662f\u4e00\u4e2a <strong>shell \u811a\u672c<\/strong>\uff0c\u79bb\u7ebf\u5b89\u88c5\u7684\u6838\u5fc3\u601d\u8def\u5c31\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5148\u628a <strong class=\"\">nvm \u4ed3\u5e93<\/strong>\uff08\u6216 nvm-windows \u7684\u53d1\u884c\u5305\uff09\u62ff\u5230\u79bb\u7ebf\u673a\u5668\uff1b<\/li>\n\n\n\n<li>\u624b\u52a8\u628a <strong class=\"\">Node.js \u4e8c\u8fdb\u5236\u5305<\/strong> \u653e\u5230 nvm \u6307\u5b9a\u7684\u76ee\u5f55\uff1b<\/li>\n\n\n\n<li>\u8ba9 nvm \u8bc6\u522b\u5373\u53ef<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u4e0b\u8f7dnvm\u6e90\u7801\u5305\u548cnode\u4e8c\u8fdb\u5236\u5305\uff0c\u5c06\u8fd9\u4e24\u4e2a\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -L -o nvm-0.39.7.tar.gz https:\/\/github.com\/nvm-sh\/nvm\/archive\/refs\/tags\/v0.39.7.tar.gz\ncurl -L -o node-v10.24.1-linux-x64.tar.xz https:\/\/nodejs.org\/dist\/v10.24.1\/node-v10.24.1-linux-x64.tar.xz<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 nvm\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.nvm    \/\/\u5f53\u524d\u7528\u6237\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u9690\u85cf\u6587\u4ef6.nvm\ntar -zxvf nvm-0.39.7.tar.gz -C ~\/.nvm --strip-components=1<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8211;strip-components=1\uff1a\u53c2\u6570\u7684\u4f5c\u7528\u662f\u89e3\u538b\u7684\u65f6\u5019\u820d\u5f03\u5916\u5c42\u76ee\u5f55\uff0c\u76f4\u63a5\u628a\u5b9e\u9645\u6587\u4ef6\u89e3\u538b\u5230.nvm\u4e0b<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a0\u4e86\u53c2\u6570\u5c31\u4f1a\u628a\u8fd9\u4e9b\u5185\u5bb9\u76f4\u63a5\u89e3\u538b\u5230.nvm\u4e0b\uff0c\u4e0d\u4f1a\u5305\u542bnvm-0.39.7\u8fd9\u4e2a\u76ee\u5f55\u4e86<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"523\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/image.png\" alt=\"\" class=\"wp-image-18942\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/image.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/image-300x241.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/image-600x482.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5728\u73af\u5883\u53d8\u91cf\u6587\u4ef6\/etc\/profile\u6216\u8005~\/.bashrc \u4e2d\u914d\u7f6e\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export NVM_DIR=\"$HOME\/.nvm\"\n&#91; -s \"$NVM_DIR\/nvm.sh\" ] &amp;&amp; \\. \"$NVM_DIR\/nvm.sh\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">source \/etc\/profile  \u6216\u8005  source ~\/.bashrc<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728nvm\u4e2d\u914d\u7f6enode\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.nvm\/versions\/node  \/\/\u521b\u5efanode\u76ee\u5f55\uff0c\u6309\u7167\u8fd9\u4e2a\u521b\u5efa\u5373\u53ef\ntar -xf node-v10.24.1-linux-x64.tar.xz -C ~\/.nvm\/versions\/node \/\/\u89e3\u538b\u5230node\u8def\u5f84\nmv ~\/.nvm\/versions\/node\/node-v10.24.1-linux-x64 ~\/.nvm\/versions\/node\/v10.24.1 \/\/\u6ce8\u610f\uff1a\u5fc5\u987b\u6539\u4e3a\u4ee5v\u5f00\u5934+\u7248\u672c\u53f7\u7684\u5f62\u5f0f\u547d\u540d<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"215\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/2-7.png\" alt=\"\" class=\"wp-image-18948\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/2-7.png 687w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/2-7-300x94.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/2-7-600x188.png 600w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u9a8c\u8bc1&amp;\u5207\u6362\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nvm ls            \/\/\u67e5\u770b\u6709\u54ea\u4e9bnode\u7248\u672c\nnvm use 10.24.1  \/\/\u6267\u884c\u5207\u6362\u547d\u4ee4\nnode -v          \/\/\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684node\u7248\u672c<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"407\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/3-6.png\" alt=\"\" class=\"wp-image-18950\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/3-6.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/3-6-300x188.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/08\/3-6-600x376.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ee\u98981: \u5728shell \u811a\u672c\u4e2d\u6267\u884cnvm\u63d0\u793anvm command not found\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nvm \u662f\u4ea4\u4e92\u5f0f\u5de5\u5177\uff0c\u53ea\u5728\u300c\u624b\u52a8\u767b\u5f55\u7ec8\u7aef\u300d\u751f\u6548\uff0c\u4e0d\u5728\u300cshell \u811a\u672c\u300d\u91cc\u751f\u6548\uff0c\u56e0\u6b64\u5982\u679c\u8981\u5728shell\u811a\u672c\u4e2d\u4f7f\u7528nvm \uff0c\u9700\u8981\u5728\u811a\u672c\u4e2d\u52a0\u8f7dnvm\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# \u52a0\u8f7d nvm\uff08\u5fc5\u987b\u5199\uff01\uff09\nexport NVM_DIR=\"\/root\/.nvm\"\n&#91; -s \"$NVM_DIR\/nvm.sh\" ] &amp;&amp; \\. \"$NVM_DIR\/nvm.sh\"\n\n# \u4e0b\u9762\u624d\u80fd\u7528 nvm \/ node \/ npm\nnvm ls\nnvm use 16\nnode -v\nnpm install\nnpm run build<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f7f\u7528Dockerfile\u6784\u5efa\u4e00\u4e2a\u591a\u7248\u672cnode\u7ba1\u7406\u5bb9\u5668\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4f7f\u7528\u5b98\u65b9 Ubuntu \u57fa\u7840\u955c\u50cf\uff08\u9009\u62e9 LTS \u7248\u672c\u66f4\u7a33\u5b9a\uff09\nFROM ubuntu:22.04\n\n# \u8bbe\u7f6e\u7ef4\u62a4\u8005\u4fe1\u606f\uff08\u53ef\u9009\uff09\nLABEL maintainer=\"your-name@example.com\"\n\n# \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\n# \u5b9a\u4e49 NVM \u7248\u672c\uff08\u53ef\u6839\u636e\u9700\u8981\u4fee\u6539\uff09\nENV NVM_VERSION v0.39.7\n# \u5b9a\u4e49\u8981\u5b89\u88c5\u7684 Node.js \u7248\u672c\uff08\u53ef\u6839\u636e\u9700\u8981\u4fee\u6539\uff09\nENV NODE_VERSION 20\n# \u8bbe\u7f6e NVM \u5b89\u88c5\u76ee\u5f55\nENV NVM_DIR \/root\/.nvm\n\n# \u914d\u7f6e\u955c\u50cf\u6e90\uff08\u53ef\u9009\uff0c\u52a0\u901f\u56fd\u5185\u4e0b\u8f7d\uff09\nRUN sed -i 's\/archive.ubuntu.com\/mirrors.aliyun.com\/g' \/etc\/apt\/sources.list &amp;&amp; \\\n    sed -i 's\/security.ubuntu.com\/mirrors.aliyun.com\/g' \/etc\/apt\/sources.list\n\n# \u66f4\u65b0\u7cfb\u7edf\u5e76\u5b89\u88c5\u4f9d\u8d56\u5de5\u5177\nRUN apt-get update &amp;&amp; apt-get install -y \\\n    curl \\\n    wget \\\n    git \\\n    ca-certificates \\\n    &amp;&amp; apt-get clean \\\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\n# \u5b89\u88c5 NVM\nRUN mkdir -p $NVM_DIR &amp;&amp; \\\n    # \u4e0b\u8f7d\u5e76\u6267\u884c NVM \u5b89\u88c5\u811a\u672c\n    curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/$NVM_VERSION\/install.sh | bash &amp;&amp; \\\n    # \u52a0\u8f7d NVM \u73af\u5883\n    . $NVM_DIR\/nvm.sh &amp;&amp; \\\n    # \u5b89\u88c5\u6307\u5b9a\u7248\u672c\u7684 Node.js\n    nvm install $NODE_VERSION &amp;&amp; \\\n    nvm install 12.22.1 &amp;&amp; \\\n    nvm install 12.22.2 &amp;&amp; \\\n    nvm install 10.16.0 &amp;&amp; \\\n    nvm install 10.24.1 &amp;&amp; \\\n    nvm install 12.22.12 &amp;&amp; \\\n    nvm install 14.21.3 &amp;&amp; \\\n    nvm install 16.20.2 &amp;&amp; \\\n    nvm install 18.20.8 &amp;&amp; \\\n    nvm install 20.20.1 &amp;&amp; \\\n    nvm install 22.22.1 &amp;&amp; \\\n    nvm install 24.14.0 &amp;&amp; \\\n    # \u8bbe\u7f6e\u9ed8\u8ba4 Node.js \u7248\u672c\n    nvm alias default $NODE_VERSION &amp;&amp; \\\n    # \u6e05\u7406\u7f13\u5b58\u51cf\u5c0f\u955c\u50cf\u4f53\u79ef\n    nvm cache clear\n\n# \u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u8ba9\u5bb9\u5668\u542f\u52a8\u65f6\u81ea\u52a8\u52a0\u8f7d NVM\nRUN echo \"\" >> \/etc\/profile.d\/nvm.sh &amp;&amp; \\\n    echo \"# Load NVM\" >> \/root\/.bashrc &amp;&amp; \\\n    echo \"export NVM_DIR=\\\"$NVM_DIR\\\"\" >> \/etc\/profile.d\/nvm.sh &amp;&amp; \\\n    echo \"&#91; -s \\\"$NVM_DIR\/nvm.sh\\\" ] &amp;&amp; \\. \\\"$NVM_DIR\/nvm.sh\\\"\" >> \/etc\/profile.d\/nvm.sh &amp;&amp; \\\n    echo \"&#91; -s \\\"$NVM_DIR\/bash_completion\\\" ] &amp;&amp; \\. \\\"$NVM_DIR\/bash_completion\\\"\" >> \/etc\/profile.d\/nvm.sh\n\n# \u5c06 Node.js \u53ef\u6267\u884c\u6587\u4ef6\u6dfb\u52a0\u5230\u7cfb\u7edf PATH\uff08\u786e\u4fdd\u975e\u4ea4\u4e92\u5f0f shell \u4e5f\u80fd\u4f7f\u7528\uff09\nENV PATH $NVM_DIR\/versions\/node\/v$(nvm version default)\/bin:$PATH\n\n# \u9a8c\u8bc1\u5b89\u88c5\n#RUN node -v &amp;&amp; npm -v &amp;&amp; nvm -v\n\n# \u8bbe\u7f6e\u9ed8\u8ba4\u547d\u4ee4\uff08\u8fdb\u5165\u4ea4\u4e92\u5f0f shell\uff09\nCMD &#91;\"\/bin\/bash\"]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u901a\u8fc7jenkins\u6784\u5efa\u524d\u7aef\u9879\u76ee\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u78b0\u5230\u4e0d\u540c\u7684\u524d\u7aef\u9879\u76ee\u4f7f\u7528\u4e0d\u540c\u7684node\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u5207\u6362\u7248\u672c\u6765\u6784\u5efa\uff0c [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":18935,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-18934","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=18934"}],"version-history":[{"count":17,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18934\/revisions"}],"predecessor-version":[{"id":19909,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18934\/revisions\/19909"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/18935"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=18934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=18934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=18934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}