Installing ngspice

The skywater SKY130 PDK requires at least ngspice version 34.
If the version of ngspice available through Ubuntu is adequate you can install it using sudo apt install ngspice.

To install the latest version download and compile ngspice from the source distribution

1. download ngspice-<xx>.tar.gz from here
(replace <xx> with the ngspice's version number you want to install, for example 41)

2. expand ngspice-<xx>.tar.gz into your home directory

tar xvfz ngspice-<xx>-tar.gz -C ~

3. ngspice requires a number of packages

  • build-essential

  • flex

  • bison

  • libx11-6

  • libx11-dev

  • libxaw7

  • libxaw7-dev

  • fontconfig

  • libxft-dev

  • libxft2

  • libcairo2

  • libcairo2-dev

  • libxmu6

  • libxext-dev

  • libxext6

  • libxrender1

  • libxrender-dev

  • libtool

  • readline-common

  • libreadline-dev

  • gawk

To check what packages are installed use apt list package-name

To install the missing packages use sudo apt install package-name

4. browse to the location of ngspice's source files and compile them using the script compile_linux.sh

cd ~/ngspice-<xx>

modify the script compile_linux.sh by adding to the ../configure command:

--prefix=/home/<your_unixusername>/opt/ngspice

and finally run the script:

./compile_linux.sh

The ../configure command inside the compile.sh script looks as follows:

../configure --prefix=/home/$(whoami)/opt/ngspice \
--with-x --enable-xspice --enable-cider --enable-predictor --enable-osdi --with-readline=yes \
--enable-openmp --disable-debug CFLAGS="-m64 -O2" LDFLAGS="-m64 -s"

The location of ngspice's binary is ~/opt/ngspice/bin

5. edit the .bash_profile file and add the ngspice's binary location to the PATH

cd ~
.bash_profile
#!/usr/bin/bash

PATH=${PATH}

# Careful:
# when there is a .bash_profile the WSL terminal does not source .bashrc by default
source ~/.bashrc

# prevent "Warning: Missing charset in String to FontSet conversion"
export LC_ALL=C

# magic: binaries location
MAGIC_BIN=$HOME/opt/magic/bin
export CAD_ROOT=$HOME/opt/magic/lib

# netgen: binaries location
NETGEN_BIN=$HOME/opt/netgen/bin

# ngspice: binaries location
NGSPICE_BIN=$HOME/opt/ngspice/bin

# PATH
PATH="$NGSPICE_BIN:$MAGIC_BIN:$NETGEN_BIN:$PATH"

# eliminate duplicates from the PATH
PATH="$(perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, $ENV{PATH}))')"

# and finally export the PATH
export PATH="$PATH"