2016-07-24 46 views
2

當我嘗試安裝NVM和測試,它的安裝在我的遊民外殼配置腳本,使用:爲什麼nvm命令是以root身份安裝的,在vagrant bootstrap.sh中也沒有找到?

sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash 
source ~/.bashrc 
nvm 

我得到:

==> default: => Downloading nvm as script to '/root/.nvm' 
==> default: => Appending source string to /root/.bashrc 
==> default: => You can now install Node.js by running `nvm install` 
==> default: /tmp/vagrant-shell: line 7: nvm: command not found 

首先,我不希望它安裝的根,我想將它安裝爲/ home/vagrant中的流浪用戶以避免許可問題。

第二個爲什麼當我運行source .bashrc時找不到命令,如在這裏的nvm安裝說明https://github.com/creationix/nvm中指定的那樣?

我有一個我現在添加的解決方案。

回答

3

因此,首先,如果你想有一個bootstrap.sh腳本期間安裝somethnig爲無業遊民用戶,做到這一點的最簡單的方法是對其他供應方腳本添加到您的Vagrantfile這是在非特權模式下運行:

config.vm.provision "ScriptRunAsRoot", type:"shell", path: "Vagrantdata/rootUserBootstrap.sh" 
config.vm.provision "ScriptRunAsVagrantUser", privileged: false, type:"shell", path: "Vagrantdata/vagrantUserBootstrap.sh" 

然後要在這種情況下獲取nvm命令,您必須確保直接運行nvm.sh腳本,即不通過nvm安裝說明中所述的.bashrc文件。這是因爲.bashrc有一條線,如果它在一個非交互式shell中運行,那麼我猜它是流浪的。從.bashrc中:

# If not running interactively, don't do anything 
case $- in 
    *i*) ;; 
     *) return;; 
esac 

因此而不是source ~/.bashrc的,你需要:

source ~/.nvm/nvm.sh 
相關問題