Skip to content

Instantly share code, notes, and snippets.

@kendrickjr
Last active January 17, 2024 10:14
Show Gist options
  • Save kendrickjr/955a43045af29fbeaede5d6914471646 to your computer and use it in GitHub Desktop.
Save kendrickjr/955a43045af29fbeaede5d6914471646 to your computer and use it in GitHub Desktop.
Install DSpace 7 Repository on Ubuntu 20.x

About Dspace 7

DSpace 7 is an open-source digital repository software system that is designed to help institutions manage and showcase their digital assets, including research papers, academic publications, datasets, multimedia content, and more. It is the latest major version of DSpace, which is widely used by universities, libraries, and other organizations to create digital repositories and archives.

DSpace 7 includes a robust search and discovery system with advanced filtering options, making it easier for users to find and access the content they need.

PREREQUISITES

The Dspace backend installation requires packages that include:

Java JDK 11 or 17 (OpenJDK or Oracle JDK)
Apache Maven 3.3.x or above (Java build tool)
Apache Ant 1.10.x or later (Java build tool)
Relational Database (PostgreSQL or Oracle)
Apache Solr 8.x (full-text index/search service)
Node.js 12 and later
Servlet Engine (Apache Tomcat 9, Jetty, Caucho Resin or equivalent)
Git (code version control)

Step 1 – Create the Dspace User

We will begin by creating a dedicated user for Dspace on our system.

sudo adduser dspace

Add the user to the sudo group:

sudo usermod -aG sudo dspace

Now switch to the created user:

sudo su - dspace

Step 2 – Install Java Runtime

We will then install Java and make the required configurations. The easiest way of installing Java 11 on Ubuntu is by executing the below commands:

sudo apt update -y

sudo apt install openjdk-11-jdk -y

Once installed, verify with the commands:

java -version

 openjdk version "11.0.20.1" 2023-08-24
 OpenJDK Runtime Environment (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04)
 OpenJDK 64-Bit Server VM (build 11.0.20.1+1-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

javac -version

javac 11.0.20.1

The next thing is to export the JAVA_HOME. Open the below file and add the lines:

nano ~/.bashrc

[...]

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin

Save the changes and source the profile:

source ~/.bashrc

echo $JAVA_HOME

/usr/lib/jvm/java-11-openjdk-amd64

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-11-openjdk-amd64/bin

Step 3 – Install and Configure PostgreSQL

Dspace uses PostgreSQL to store its data. Dspace has been tested on PostgreSQL 11, 12 and 13. For this guide, we will use PostgreSQL 13 which can be installed by following the guide below:

**Install PostgreSQL on Ubuntu **

Ensure all the required packages have been installed:

sudo apt install postgresql postgresql-contrib libpostgresql-jdbc-java -y

Once installed, we will allow the host to access the PostgreSQL server:

echo "host dspace dspace 127.0.0.1/32 md5" | sudo tee -a /etc/postgresql/*/main/pg_hba.conf

We will also set several user permissions:

> sudo sed -i 's/ident/trust/' /etc/postgresql/*/main/pg_hba.conf
> sudo sed -i 's/md5/trust/' /etc/postgresql/*/main/pg_hba.conf
> sudo sed -i 's/peer/trust/' /etc/postgresql/*/main/pg_hba.conf

After that, restart the PostgreSQL service:

sudo systemctl restart postgresql

Switch to the Postgres user:

sudo su - postgres

Create a database user and database for DSpace:

createuser dspace

createdb dspace -E UNICODE

Now access the shell:

psql -d dspace

Create the pgcrypto extension:

CREATE EXTENSION pgcrypto;

Create the password for the user and assigned the required permissions:

ALTER ROLE dspace WITH PASSWORD 'Passw0rd';

ALTER DATABASE dspace OWNER TO dspace;

GRANT ALL PRIVILEGES ON DATABASE dspace TO dspace;

Exit the shell:

\q

Exit the Postgres user:

exit

Restart PostgreSQL:

sudo systemctl restart postgresql

Step 4 – Install Apache Solr 8 >

To install Apache Solr 8 on Ubuntu, you need to download it from the Apache Solr downloads page. You can also download it using the command line:

wget -c https://dlcdn.apache.org/lucene/solr/8.11.2/solr-8.11.2.tgz

Extract file

tar xvf solr-*.tgz

Install Apache Solr:

sudo bash solr-8.11.2/bin/install_solr_service.sh solr-8.11.2.tgz

A symbolic link is created in /opt/solr after this.

Step 5 – Install Tomcat 9

Tomcat is also one of the main requirements of DSpace. For this guide, we will install Apache Tomcat 9 which exists in the default Ubuntu repositories:

sudo apt install tomcat9

Here, we need to define our JAVA_HOME and memory limits:

sudo nano /etc/default/tomcat9

In the file, make the below changes:

JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -Xms1024m -XX:MaxPermSize=1024m"
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

We also need to modify the below file:

sudo nano /etc/tomcat9/server.xml

Modify the lines below:

<Connector port="8080" 
 minSpareThreads="25"
          enableLookups="false"
          redirectPort="8443"
          connectionTimeout="20000"
          disableUploadTimeout="true"
          URIEncoding="UTF-8"/>

Step 6 – Install Git, Maven and Ant

Maven is used to compile the Dspace 7 code, It also downloads all the required dependencies for Dspace. Ant on the other hand installs the compiled code.

To install them on Ubuntu, use the command:

sudo apt install ant ant-optional maven git -y

Verify the installation:

mvn -v

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.20.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-79-generic", arch: "amd64", family: "unix"

ant -version

Apache Ant(TM) version 1.10.12 compiled on January 17 1970

Step 7 – Install DSpace 7 Backend

Proceed and download the latest version of DSpace Backend from the DSpace GitHub Repository. For this guide, we will use v7.2 which can be pulled with the command:

wget -c https://github.com/DSpace/DSpace/archive/refs/tags/dspace-7.6.1.tar.gz

Extract the archive:

tar -zxvf dspace-*.tar.gz

Rename the folder to a simpler name:

mv DSpace-dspace-* dspace-7-src

Now navigate to the directory:

cd dspace-7-src

Create a directory for the deployment:

sudo mkdir /opt/dspace-7

Set the ownership to the DSpace user:

sudo chown dspace:dspace -R /opt/dspace-7

Create a configuration file from the default available one:

cp dspace/config/local.cfg.EXAMPLE dspace/config/local.cfg

Modify this configuration file:

nano dspace/config/local.cfg

Make the below adjustments:

dspace.dir=/opt/dspace-7
dspace.server.url = http://YOUR-SERVER-IP:8080/server
dspace.ui.url = http://YOUR-SERVER-IP:4000
dspace.name = DSpace at ComputingforGeeks
solr.server = http://localhost:8983/solr
db.url = jdbc:postgresql://localhost:5432/dspace
db.driver = org.postgresql.Driver
db.username = dspace
db.password = Passw0rd

Once the adjustments have been made, start building Dspace:

mvn package

Sample Output:

 Build Succesfull 

Navigate to the created installer directory:

cd dspace/target/dspace-installer

Deploy the generated code:

ant fresh_install

Sample Output:

BUILD SUCCESFULL

Once complete, configure Tomcat9 to serve DSpace:

cd /var/lib/tomcat9/webapps

sudo ln -s /opt/dspace-7/webapps/server server

You also need to copy the configs to Solr:

sudo cp -r /opt/dspace-7/solr/* /opt/solr/server/solr/configsets

Restart Apache Solr:

sudo systemctl restart solr

Run database migrations:

cd /opt/dspace-7

./bin/dspace database migrate

Next we create admin user.

/opt/dspace-7/bin/dspace create-administrator

Creating an initial administrator account

E-mail address: [email protected]
First name: test
Last name: user
Password will not display on screen.
Password: 
Again to confirm: 
Is the above data correct? (y or n): y
Administrator account created

Now you can access the DSPace Backed using the URL http://IP_Address:8080/server

Step 8 – Install Dspace 7 Front End

When installing the Dspace 7 Front End, you need some packages. One of these packages is NodeJS. Dspace 7 works with Node.js (v16 or v18) and required Dspace 7 and above.

Here, we will install Node.JS using NVM installed with the command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

Source the profile:

source ~/.bashrc

Now install Node.JS 16 LTS

nvm install v16

Check the node.js version:

node --version

v16.20.0

npm -v

8.19.4

Install NPM from the PAT repo:

sudo apt install npm

Also, install Yarn and PM2:

sudo npm install --global yarn

sudo npm install --global pm2

Download DSpace Frontend from the GitHub releases page. You can also pull it with Wget:

cd ~
wget -c https://github.com/DSpace/dspace-angular/archive/refs/tags/dspace-7.6.tar.gz

Once downloaded, extract it:

tar -zxvf dspace-*.tar.gz

Rename the directory with a more straightforward name:

mv dspace-angular-dspace-* dspace-7-angular

Navigate into the directory:

cd dspace-7-angular

Instal all the required dependencies:

yarn install

Once installed, start the build process:

yarn build:prod

Sample Output:

  done!

Now copy the generated files to it to a dedicated directory in /opt

sudo cp -r ../dspace-7-angular/ /opt/dspace-7-angular

Set the correct permissions:

sudo chown dspace:dspace -R /opt/dspace-7-angular/

Now we need to configure PM2:

cd /opt/dspace-7-angular/

nano dspace-ui.json

In the file, add the below lines

{
    "apps": [
        {
           "name": "dspace-angular",
           "cwd": "/opt/dspace-7-angular",
           "script": "yarn",
           "args": "run serve:ssr",
           "interpreter": "none"
        }
    ]
}

Save the file and create a config so that the Frontedn can communicate with the backed:

nano config/config.yml

Modify the values to match your Dspace server:

rest:
  ssl: false
  host: DSpace-IP_Address
  port: 8080
  nameSpace: /server

Start the Dspace Front end:

pm2 start dspace-ui.json

At this point, you will have the Dspace listening on port 4000, localhost

Step 9 – Configure Nginx Reverse Proxy

To be able to access the Dspace Frontend using the domain name or IP address, we need to configure a reverse proxy. For this guide, we will use Nginx.

Install Nginx on Ubuntu with the command:

sudo apt install nginx -y

Create a virtual host file:

sudo nano /etc/nginx/conf.d/dspace_ui.conf

Add the below lines replacing your domain name/IP address appropriately:

server {
  listen 80;
  server_name    YOUR-DOMAIN-NAME;
  access_log /var/log/nginx/dspace-access.log;
  error_log /var/log/nginx/dspace-error.log;

location / {
    proxy_pass http://localhost:4000/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Once created, restart nginx:

sudo service nginx restart

Step 10 – Access Dspace 7 Front End

Now you should be able to access your Dspace 7 Frontend using your domain name or IP address. For example //dspace.navitrack.co.tz

In case you find error 500, you need to modify the dspace.ui.url on your Dspace Backend to match what you are trying to access the  
server with. You can then log in using the admin we created earlier. First, accept the license terms and thats it!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment