I am trying to install NVM on AWS Ubuntu 18.04 AMI using a bash script. So I have created a bash script named before_install.sh and written this piece of code.
 #!/bin/bash
 if ! [ -x "$(command -v nvm)" ]; then
    echo "Error: 'nvm' is not installed." >&2
    echo "Installing nvm ..."
    wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
 else
    echo "'nvm' tool is already found"
 fi
But when I  execute this script using bash before_install.sh and I checked whether nvm is installed or not by using commands such as command -v nvm or nvm --version, It shows that nvm that no package named nvm is available even when it is installed. However, through some research, I identified and added source .bashrc after nvm installation at the end in the bash script. But still, I have to run source .bashrc again manually in the terminal and then nvm works.
Why nvm is behaving like this or what is the cause of problem.