【问题标题】:Closing the terminal doesnt remember my .profile changes for nvm/npm关闭终端不记得我对 nvm/npm 的 .profile 更改
【发布时间】:2016-02-19 19:20:30
【问题描述】:

我使用这条指令安装了 nvm/npm

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server(如何使用 NVM 安装),但是每次我关闭终端时,似乎都忘记了所有设置,我必须执行以下命令: source ~/.profile 然后选择 npm 版本以使其再次运行。如何保持我的设置永久不变,或者至少在我登录会话期间保持不变?谢谢! (linuxmint 17)

【问题讨论】:

    标签: node.js npm linux-mint


    【解决方案1】:

    采购 ~/.profile

    ~/.profile 通常从登录 shell 调用。见http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

    作为交互式登录 shell 调用,或与 --login 一起调用

    当 Bash 作为交互式登录 shell 或作为带有 --login 选项的非交互式 shell 调用时,它首先从文件 /etc/profile 中读取并执行命令(如果该文件存在)。读取该文件后,它会按顺序查找 ~/.bash_profile、~/.bash_login 和 ~/.profile,并从第一个存在且可读的文件中读取并执行命令。启动 shell 时可以使用 --noprofile 选项来禁止这种行为。

    打开终端通常不会调用登录 shell。您是否尝试过重新启动/重新登录?此外,如果 ~/.bash_profile 或 ~/.bash_login 存在,那么 bash 将不会获取 ~/.profile。解决此问题的常用方法有两种:

    选项 1

    将命令从~/.profile 文件移动到~/.bash_profile

    选项 2

    来源~/.profile来自~/.bash_profile:

    [[ -f ~/.profile ]] && . ~/.profile
    

    默认节点版本

    您可以通过将其别名为 default 来配置默认节点版本

    要设置在任何新 shell 中使用的默认 Node 版本,请使用别名 'default':

    nvm alias default node
    

    见https://github.com/creationix/nvm

    【讨论】:

    • 嗨乔纳森,同样的事情仍然发生。我应该将它包含在启动程序中并添加该命令吗?
    • 根据上面引用的 bash 文档,如果您有 ~/.bash_profile 或 ~/.bash_login 文件,则不会获取 ~/.profile。
    • 我已更新我的答案,以提供更多关于采购 ~/.profile 文件的说明。
    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多