Intro
Bypassing any discussions about choosing Visual Studio Code (VS Code) over Atom or Sublime Text, here’s how to install VS Code on Linux.
Ubuntu / Mint
#Update system before installation
sudo apt -y update && sudo apt -y upgrade
#
#Install the prerequisites
sudo apt -y install software-properties-common apt-transport-https wget
#
# Import Microsoft GPG key
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
#
# Enable VS Code repository
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode/ stable main"
#
# Perform the install
sudo apt -y install code
# Bonus: Install DotNet Core
#
# Register with Microsoft
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
#
# Install the .NET SDK
sudo apt-get -y install apt-transport-https
sudo apt-get -y update
sudo apt-get -y install dotnet-sdk-2.2
# Associate DotNet with VS bash Code
scl enable rh-dotnet22 bash
scl enable rh-dotnet22 code
# Permanently enable .NET Core in your development environment
cat <<EOF > ~/.bashrc
# Add .NET Core 2.2 to my login environment
source scl_source enable rh-dotnet22
EOF
Red Hat Family (RHEL 7):
# Import Microsoft Repo
rpm --import https://packages.microsoft.com/keys/microsoft.asc
#
# Activate Repo with Microsoft GPG
sh -c 'echo -e "\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo
#
# Update before install
yum update
#
# Install VS Code
yum install code
# Bonus: Install Dot Net Core
#
# Subscribe to DotNet Core
subscription-manager repos --enable=rhel-7-server-dotnet-rpms
#
# Install DotNet Core
yum install -y rh-dotnetcore22
#
# Associate DotNet with VS bash Code
scl enable rh-dotnet22 bash
scl enable rh-dotnet22 code
# Permanently enable .NET Core in your development environment
cat <<EOF > ~/.bashrc
# Add .NET Core 2.2 to my login environment
source scl_source enable rh-dotnet22
EOF
Launch VSC from CLI
code &
Check that VS Code is running
kim@nuc:~$ pgrep code
16191
16193
16225
16240
16266
16283
[1]+ Done code
Adding Components
Launch VS Code > click on View > Extensions > Browse through the list and install any components required for the project (e.g. Docker, Python, JavaScript ES6, NodeJS Module Intellisense, Angular6, Angular7, Regex Previewer, HTML CSS Support)
Troubleshooting
Sometimes, this error would occur:
kim@nuc:~$ sudo apt update
InRelease [88.8 kB]
Fetched 275 kB in 1s (205 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:58 and /etc/apt/sources.list.d/vscode.list:3
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:58 and /etc/apt/sources.list.d/vscode.list:3
Reading the error code, it seems that /etc/apt/sources.list:58 & /etc/apt/sources.list.d/vscode.list:3 are containing duplicating records. After verifying this issue, the fix is to simply remove one of the two redundant entries.
kim@nuc:~$ cat /etc/apt/sources.list.d/vscode.list
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb [arch=amd64] https://packages.microsoft.com/repos/vscode/ stable main
kim@nuc:~$ grep -i vscode /etc/apt/sources.list
deb [arch=amd64] https://packages.microsoft.com/repos/vscode/ stable main
# deb-src [arch=amd64] https://packages.microsoft.com/repos/vscode/ stable main
kim@nuc:~$ rm -f /etc/apt/sources.list.d/vscode.list
rm: cannot remove '/etc/apt/sources.list.d/vscode.list': Permission denied
kim@nuc:~$ sudo rm -f /etc/apt/sources.list.d/vscode.list
kim@nuc:~$ sudo apt -y update
Ign:1 stable InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu/ disco InRelease
Hit:3 stable Release
Get:4 http://us.archive.ubuntu.com/ubuntu/ disco-updates InRelease [97.5 kB]
Get:5 http://security.ubuntu.com/ubuntu/ disco-security InRelease [88.4 kB]
Hit:6 https://packages.microsoft.com/repos/vscode/ stable InRelease
Get:8 http://us.archive.ubuntu.com/ubuntu/ disco-backports InRelease [88.8 kB]
Fetched 275 kB in 1s (206 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.