您当前所在位置:首页linux如何在linux中轻松安装node?

如何在linux中轻松安装node?

更新:2024-04-24 09:30:34编辑:jiang归类:linux人气:19

1.先下载 node 当然下载的是符合linux 系统的 我当时下载的是 node-v16.18.0-linux-x64.tar.xz

2. 把 node-v16.18.0-linux-x64.tar.xz 放到linux 服务器上 我当时是用ftq 放到了 /usr/local文件夹下新建了一个 node 文件

3.解压 node-v16.18.0-linux-x64.tar.xz 必须在linux 服务器上解压。在window 中解压再放上去使用npm 会报错 解压代码 tar -xJvf node-v16.18.0-linux-x64.tar.xz

4.配置 全局路劲PATH 在 /etc/profile 文件进行如下设置 注释:(主要看pathmunge 函数的使用不会的可以百度查一下linux 函数使用)把node文件里面bin 路劲添加到全局路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pathmunge /usr/local/linuxNode/node-v16.18.0-linux-x64/bin after
 
# /etc/profile
  
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
  
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
#pathmunge 是Linux 函数  
pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if "$2" "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}
  
  
if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi
  
# Path manipulation 
#$EUID 是全局变量 判断用户是否具有权限
if "$EUID" "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi
  
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if "$HISTCONTROL" "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi
  
#使用 pathmunge 函数 
pathmunge /usr/local/linuxNode/node-v16.18.0-linux-x64/bin after
  
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
  
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if $UID -gt 199 ] && [ "`/usr/bin/id -gn`" "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi
  
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if "${-#*i}" != "$-" ]; then 
            "$i"
        else
            "$i" >/dev/null
        fi
    fi
done
  
unset i
unset -f pathmunge

5.进行 刷新 source /etc/profile

6.进入到我们按钮的node 文件的bin 文件 进行权限分配。chmod +x node 或者 chmod +x node

我告诉你msdn版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

linux
linux删除目录文件夹使用哪条命令 在Linux中如何安装PHP的memcache扩展?

游客 回复需填写必要信息