Skip to content

Commit

Permalink
Add NVM path to .bashrc file (#38)
Browse files Browse the repository at this point in the history
### What was the problem?

This PR resolves LISK-944.

### How was it solved?

If `NVM_DIR` is not set inside `.bashrc` file, it is added.
  • Loading branch information
matjazv authored Aug 15, 2024
1 parent 12ce042 commit 354f236
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions scripts/installDependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@ fi
# Function to install NVM
install_nvm() {
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Add NVM load commands to .bashrc
if [ ! -f "$HOME/.bashrc" ];
then
touch $HOME/.bashrc
fi
if [ $(grep NVM_DIR "$HOME/.bashrc" | wc -l) -ge 2 ];
then
echo "NVM commands are already added to .bashrc"
else
echo "export NVM_DIR=\"\$HOME/.nvm\"" >> "$HOME/.bashrc"
echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\" # This loads nvm" >> "$HOME/.bashrc"
fi

# Ensure NVM is now available in PATH
source "$HOME/.bashrc"
}

install_node_version() {
# Setting up environment for NVM
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"

# Check if NVM is installed
if [ -s "$NVM_DIR/nvm.sh" ];
then
Expand All @@ -31,9 +44,6 @@ install_node_version() {
install_nvm
fi

# Load NVM
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

echo "Installing Node version $node_version..."
nvm install $node_version
nvm alias default $node_version
Expand Down

0 comments on commit 354f236

Please sign in to comment.